How to make JavaFX TableView cells editable? - javafx-2

There are a lot of tutorials, And a lot of suggestions to achieve this by extending JavaFX cells to make them editable. A good one is this stackoverflow question.
But the official tutorials uses a method call to create the callback without writing all that code, By calling
lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
However when I do this in my code (FormTokens is my "model"):
// At beginning of class declaration
#FXML private TableColumn<FormTokens, String> valuColumn;
// Later at initialization
valuColumn.setCellFactory(TextFieldTableCell.forTableColumn());
Compiler says:
The method
setCellFactory(
Callback<TableColumn<FormTokens,String>,TableCell<FormTokens,String>>)
in the type TableColumn<FormTokens,String>
is not applicable for the arguments
(Callback<TableColumn<Object,String>,TableCell<Object,String>>)
If I remove the method call mentioned above everything works well except that TableView cells are not editable. What am I doing wrong?
edit: I just found this: Javafx TableView can not be edited But there are no solutions. How do I cast Callback<TableColumn<Object,... to Callback<TableColumn<FormTokens,...?

Specify the exact type explicitly for generic parameter as
valuColumn.setCellFactory(TextFieldTableCell.<FormTokens>forTableColumn());

Related

Custom Collection View is not showing up

I'm working on an app that'll have a range of images and the collectionview is not showing up at all. I was following this article, which I translated to C#.
here is an example app I made to show a minimal example of what I'm trying to do.
When I run through the code, GetCell in the collection source isn't firing which I know is the problem, but I don't know why it's not firing and I'm simply at a lost on what I'm missing.
I test it again today and I can make sure that the problem is caused by the MosaicCollectionLayout.
What I did today is that I removed your collectionView and add a new collectionView, then I add Constrains to it with a fixed height and width(to make sure it appears even if there is no data), then I change the layout to FlowLayout, it works, here is the screenshot:
After that, I changed the layout back to MosaicCollectionLayout, I get an exception in the line _cachedAttributes.Reverse(lastIndex.Row, firstMatchIndex.Value); inside the method LayoutAttributesForElementsInRect.
I checked the article and did not find a solution yet. Maybe there is some mistakes in the codes translated from swift to C#. So the problem is not related to the xib, please check the code in the method LayoutAttributesForElementsInRect.You can also try add Constrains to your collectionView. Hope these information helps you.

Xamarin iOS : How to detect the tableview scroll

I want to detect the scroll of tableview in my class. I used decelerationEnded method of UITableViewDelegate but it got crashed.
Ideally you should be using a UITableViewSource assigned to your UITableView.Source property. You no longer require a delegate class, you can override all of the necessary methods within the source, which is the currently preferred method of achieving the result your after. You are most likely looking to override the method called 'Scrolled' within the UITableViewSource. However I would suggest making use of 'DecelerationEnded' as well if you're trying to do something depending on if your scroll view is at the 'bottom' or 'top' of the UITableViews content (That's just a little tip based off of some experience with this in a recent project.)

Passing an object from a tabbarController to its subviews

I am trying to pass a simple core data objects info from a tabBarController to its subviews so that they each reference a different attribute of that object. As a newbie, I'm not sure even where to start. It doesn't seem to be as simple as passing the data from one tableView to another...
Thank you for any help.
If you are sharing the same object between (most of the) the view controllers of your tab bar controller, maybe the best architecture for this would be to have one central data object.
A typical pattern is a singleton, some kind of data manager that provides the object, but maybe that is overkill. Another is to keep references to all view controllers and update them one by one when something changes - also not very elegant.
What you really want is something like a global variable. You could (ab)use your app delegate (just give it a property that points to the object) or if you prefer even your tab bar controller (make a subclass, give it a property). In the latter case, every view controller could then get the object like this:
NSManagedObject *object = [(MyCustomTabBarController*)self.tabBarController object];
For example, you can check for changes and refresh your views in viewWillAppear.
A UITabBarController should be handling other view controllers, not handling data objects. How does the tab bar controller get the object reference in the first place? And what is the object you're sharing?
Let each of your subordinate VC's keep a pointer to the object, and then they can each follow the appropriate keypath to get to the entities they're designed to handle.
Tim Roadley's book Learning Core Data for iOS, in chapters 5 and 6, shows how to pass an object from one view controller (a table view) to a detail view. It doesn't sound like that's what you're asking, but just in case...
In response to comment:
I'm looking at a tableview, tap a cell, and then a tab bar controller slides in? That's not the usual visual metaphor for a tab bar; it's meant for changing modes for the entire program. See the Music app for a typical example: songs, playlists, artists.
But if you really need to do it that way, try this (I'm assuming you're using storyboards):
In prepareForSegue: in your tableview controller, tell the destination (tab bar controller) what object it's working with.
In the tab bar controller's -viewWillAppear, tell each of its tabs about the attribute: self.frobisherViewController.frobisher = self.myWidget.frobisher.
You could instead tell each of the component tabs about the top level object: self.frobisherViewController.widget = self.myWidget. But I like the first approach better because there is less linkage. The frobisherViewController now would need to know about both widgets and frobishers.
This ended up being very simple. I was trying to call the object in the child views initWithNibName which doesn't work. I ended up creating a setObject function and calling the properties I wanted in viewWillAppear.
Hope this helps someone.

extend class in Java FX?

In many occasions JavaFX needs to be customized with classes that extend existing ones. I tried this approach, for example to add a method to the NumberAxis class that would enable the label of the axis to be rotated.
But I got a "NumberAxis is declared final, can't be extended" compiler error. I wonder how people who extend classes do? Do they have access to the source code of javafx, modify it to make some classes not final, and recompile it? (sounds tricky! )
Making lots of classes final in the JavaFX framework was an intentional decision by the framework developers. To get a flavor of why it's done, see the Making Color Final proposal. That's just an example, there are other reasons. I think experience with subclassing in the Swing framework was that it caused errors and maintenance issues that the JavaFX designers wanted to avoid, so many things are made final.
There are other way to extend functionality than to directly subclass. Some alternatives for your rotation example:
aggregation: include the NumberAxis as a member of new class (e.g. NumberAxisWithRotatableText) which adds an accessor to get the underlying NumberAxis node and a method to perform the rotation (e.g. via a lookup as explained below).
composition: for example extend Pane, add a NumberAxis, disable the standard text drawing on the axis and add rotated labels yourself as needed.
css stylesheet: for example use a selector to lookup the text in the NumberAxis and the -fx-rotate attribute to rotate it.
node lookup: Use a node.lookup to get at the underlying text node, and apply the rotation via an API.
skin: All controls have a skin class attached them, replace the default skin class with a custom one.
subclass an alternate class: Subclass the abstract ValueAxis class rather than the final NumberAxis class.
Source code for JavaFX is available with build instructions. However, I don't recommend hacking a personal copy of the source code to remove final constructs unless you also submit it as an accepted patch to the JavaFX system so that you can be sure that your app won't break on a standard JavaFX install.
If you really think it is a good idea for a given class to be subclassable, then log a change request. Sometimes the JavaFX developers are overzealous and make stuff final which would be better not being final. NumberAxis perhaps falls into that category.

How to use UITableViewDelegate.AccessoryButtonTapped (with Monotouch)

I'm creating an IPad application using C#, Mono develop and Monotouch.
I've been using Monotouch.Dialog to create functionality similar to the wifi-settings on an iPhone. I'm using StyledStringElement with an accessory and am now trying to differentiate between tapping the row and tapping the DetailDisclosureButton.
I've been found out that I should override the UITableViewDelegate.AccessoryButtonTapped on the UITableView. I've tried to created a derived class from UITableViewDelegate and hook this into the Monotouch.Dialog. But this is where I got stuck. I didn't manage to replace the existing UITableViewDelegate with my extended version.
So my questions are:
Is this the preferred way of handling this event (to be able to differentiate between a tap on the element and a tap on the DetailDisclosureButton) ?
If not, any pointer on how to accomplish this ?
I have been searching the web for a (similar) example but have not found any yet. Any examples that you know of that could get me started ?
Thanks,
boris
event EventHandler accessoryPushed;
public override void AccessoryButtonTapped (UITableView tableView, NSIndexPath indexPath)
{
if(!accessoryPushed)
{
accessoryPushed(this,EventArgs.Empty);
}
}
You will need to add this to the DailogViewController code that you are using (this will override the tapping action). Instead of a simple function, you may want an event to be triggered, so just handle the event in your main code. That is probably your best bet.
Once you change this line, you will have to implement new functions like AccessorySelected (just mimic the path the code follows when a row is selected except with accessory).
On the other hand, you could try a different navigation method, often disclosure buttons are annoying and you don't want to click on them except to get simple information about the button (like a help feature).
I haven't found any other examples, sorry!

Resources