Skip to content

Add support for FXML (again)#654

Merged
JordanMartinez merged 12 commits intoFXMisc:masterfrom
Jugen:patch-1
Nov 24, 2017
Merged

Add support for FXML (again)#654
JordanMartinez merged 12 commits intoFXMisc:masterfrom
Jugen:patch-1

Conversation

@Jugen
Copy link
Copy Markdown
Collaborator

@Jugen Jugen commented Nov 22, 2017

Fixed regression part of #653

Fixed regression part of #653
@JordanMartinez
Copy link
Copy Markdown
Contributor

Looks like you'll need to revert the default methods back to regular interface method declarations

Could you add a test in this PR, too, that initializes an area with all the FXML configurations? That should insure this doesn't get broken in the future. I'm not sure whether such a test should go in the regular test package or in the integrationTest package.

@Jugen
Copy link
Copy Markdown
Collaborator Author

Jugen commented Nov 22, 2017

I've never submitted a test before, so need some guidance:

  1. Does the test need to be registered somewhere or are all class files that have a main method in RichTextFX/richtextfx/src/integrationTest/.../org/fxmisc/richtext automatically executed ?
  2. Do you have to have a method annotated with @Test ?

@JordanMartinez
Copy link
Copy Markdown
Contributor

Mm... yeah I guess this should go in the integrationTest package. I suppose the test class should also go in the api package within integrationTest since this doesn't fall into behavior-related tests, nor is it expansive enough to need its own package.

So, create a new class that extends RichTextFXTestBase (or whatever it's called).
Add a start method that is similar to InlineCssTextAreaAppTest's start method, but without the area or its helper methods.
Add a method that has a name format like "tests_whether_fxml_construction_of_area_works()" that is annotated with @Test. In its body, you could use the FXML loader to create an area, which is then assigned to the stage's root. Then, you could assert that certain properties are true (e.g. it has a context menu, it's text is wrapped, etc.)

In case you're wondering, some test classes are annotated with @RunWith(NestedRunner.class) because it allows one to set up contexts that get shared between multiple tests. Since this is a single test, it's not needed.

Copy link
Copy Markdown
Contributor

@JordanMartinez JordanMartinez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your work is almost done. Good job so far.

Were you planning to change the Consumer objects to EventHandler objects, too?

When the PR is complete, I'll ask you to reduce the commit history to the smallest amount of commits that is sensible and to reword some of their messages to better explain what you did in each one. Don't worry about this step until everything else has been taken care of, so that you don't waste your time on it.

// FxmlTest.fxml is located in resources folder:
// src/integrationTest/resources/org/fxmisc/richtext/api/
try { obj = FXMLLoader.load( getClass().getResource( "FxmlTest.fxml" ) ); }
catch ( Exception EX ) { EX.printStackTrace(); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be a catch here. Rather, the test method should propagate the thrown exception:

@Test
public void testSomething() throws IOException {
// no longer need the try or catch statements
// try { 
    FXMLLoader.load();
// } catch (IOException EX) {}

Also, it should throw the exception that FXMLLoader.load will throw, not the base Exception class upon which all other exceptions are based.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do ....

<?import javafx.scene.control.ContextMenu?>
<?import javafx.scene.control.MenuItem?>

<VBox xmlns:fx="http://javafx.com/fxml/1">
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To prevent noise, it should return a single area, not a VBox of two areas.


<VBox xmlns:fx="http://javafx.com/fxml/1">
<StyleClassedTextArea editable="true" wrapText="true" autoScrollOnDragDesired="true" />
<StyleClassedTextArea contextMenuXOffset="12.0" contextMenuYOffset="34.0" >
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two sets of properties should be combined into the same area

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, I did it this way because I thought its easier to read than having one long line of properties :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be a one-liner? Could you do something like

<StyleClassedTextArea
    editable="true"
    wrapText=true"
    ... 
    <contextMenu>...</contextMenu>
</StyleClassedTextArea>

Object obj = null;
// FxmlTest.fxml is located in resources folder:
// src/integrationTest/resources/org/fxmisc/richtext/api/
try { obj = FXMLLoader.load( getClass().getResource( "FxmlTest.fxml" ) ); }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return an area (you'll need to cast the returned object into what it actually is) so we can assert that its properties are what they were specified to be in the FXML document.

// src/integrationTest/resources/org/fxmisc/richtext/api/
try { obj = FXMLLoader.load( getClass().getResource( "FxmlTest.fxml" ) ); }
catch ( Exception EX ) { EX.printStackTrace(); }
org.junit.Assert.assertNotNull( obj );
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should assert that the properties values are what we specified them to be.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If FXMLLoader cannot set a property it will throw an exception, so if no exception is thrown then it's guaranteed to have been set :-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. Mind writing that in as a comment for those of us who don't use it that often?

@Jugen
Copy link
Copy Markdown
Collaborator Author

Jugen commented Nov 23, 2017

Were you planning to change the Consumer objects to EventHandler objects, too?

Yes, I've done that in a separate branch. I was going to do a PR once this one is done ?

@JordanMartinez
Copy link
Copy Markdown
Contributor

Yes, I've done that in a separate branch. I was going to do a PR once this one is done ?

Ok. Yeah, I guess that falls into a slightly different scope that this one despite still being FXML related. We should open a separate issue for that, too, so that it shows up in the generated changelog.

@JordanMartinez
Copy link
Copy Markdown
Contributor

Is there a reason for wrapping the area in a VBox?

@Jugen
Copy link
Copy Markdown
Collaborator Author

Jugen commented Nov 23, 2017

It could have been any Pane subclass (think Swing layout manager). Originally I had it as a BorderPane, until I wanted to add multiple text areas and made it a VBox for simplicity. Technically it's possible for it to be a Control, although it doesn't usually make sense.

Bear in mind that the FXML file is still going to change in order to accommodate testing the EventHandlers, so if you don't mind I'd prefer to keep it as is for now. We can look at changing it then, if you still think it would be better.

@JordanMartinez
Copy link
Copy Markdown
Contributor

Looks good! Thank you for your work.

@JordanMartinez JordanMartinez changed the title Fix for #653 (phase one) Add support for FXML (again) Nov 24, 2017
@JordanMartinez JordanMartinez merged commit 08ff468 into FXMisc:master Nov 24, 2017
@Jugen Jugen deleted the patch-1 branch November 24, 2017 12:15
@JordanMartinez
Copy link
Copy Markdown
Contributor

I just realized that I forgot to ask you to squash your commits into as few as possible before merging... My bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants