Vaadin filter Date Column - java

I am using Vaadin 15. In my application I am using a grid, which uses a dataprovider (data) to show a bunch of different columns. Further, I am using a filter to filter all columns. One Column consists of dates, with my current Filter Function i can not filter ranges.
I am very new to Java and programming in general. This is the filter function I use currently.
TextField cas=getFilters(casColumn,filter);
cas.addValueChangeListener(event-> data.addFilter(dataRecord-> StringUtils.containsIgnoreCase(dataRecord.getCas(), cas.getValue())));
Now I would like to also be able to filter ranges of dates. So in the filter TextField a date is given and everything till today will be shown, everything older than the date will not be shown.
Thanks for your help. Tipps for some literature on how to do it are also appreciated.

I am using Vaadin 15.
Just pointing out that it makes little sense to use Vaadin 15, as it is not supported anymore. The latest version Vaadin 21.
With the newest Vaadin versions if you are using in memory data provider Grid is set up using
GridListDataView<Data> dataView = setITems(data); // where data is a collection of
items
Then you can set the filter you use via dataView, say
textField.addValueChangeListener(event -> {
dataView.setFilter(item-> item.getProperty().equals(event.getValue));
});
Note, if you have data provider from callbacks, then above method does not apply for you , instead filtering is done as follows, i.e. providing a query that can use the value of the filter
TextField filter = new TextField("Filter");
filter.setValueChangeMode(ValueChangeMode.LAZY);
filter.addValueChangeListener(event -> {
grid.setItems(query -> personService
.fetch(query.getOffset(), query.getLimit(), event.getValue()).stream(),query -> personService.count(event.getValue()));
});

Related

Search in one GWT ComboBox affects on other ComboBox with the same store

I'm using com.extjs.gxt.ui.client.widget.form.ComboBox GWT version 2.8.2 and gxt 2.3.1a .
I have 2 comboboxes that have the same storage with many values. When I do search in one combobox I see in debug ComboBox lastquery value same as in search string and only single found value in the CombobBox store. But same value I see in other CombobBox which use same storage. So when I'm trying to work with other comboboxes connected (by listener) to second combobox I get an error because I can't load the required values.
com.google.gwt.core.client.JavaScriptException: (TypeError) : Cannot read properties of null (reading 'getValue__Ljava_lang_Object_2')
at Unknown.TypeError: Cannot read properties of null(Unknown#-1)
Maybe some option exists to allow to use of the same storage in several ComboBoxes without affecting each other, i.e. not limit storage with filtered by search string values? Using 2 storages by creating 2 copies is not preferable. Thanks in advance.
UPD: combobox2.getValue() gives null when search was performed earlier. How I can reload storage in this case?
UPD: I created 2 comboboxes with the same storage:
private final ListStore<ComboBoxItemModel<String>> countryStore;
public ComboBox<ComboBoxItemModel<String>> createCountryCombobox() {
ComboBox<ComboBoxItemModel<String>> countriesComboBox = new ComboBox<>();
countriesComboBox.setFieldLabel("Country");
countriesComboBox.setStore(countryStore);
countriesComboBox.setAllowBlank(false);
countriesComboBox.setTriggerAction(ComboBox.TriggerAction.ALL);
countriesComboBox.setDisplayField(ComboBoxItemModel.COMBO_BOX_ITEM_NAME);
countriesComboBox.setValue(countriesComboBox.getStore().getAt(0));
countriesComboBox.setForceSelection(true);
countriesComboBox.setEditable(true);
return countriesComboBox;
}
setEditable(true) option allows to search countries in the list, but it delete values in the storage as result. So I can't load values for other fields connected to second combobox without manual selection in combobox2.
Seems using two storage is quite a simple solution. Other solutions that I tried look like a workaround. I just create copies and it works fine:
ListStore<ComboBoxItemModel<String>> store = new ListStore<>();
store.add(countryStore.getModels());
countriesComboBox.setStore(store);

JavaFX filtering categories

I'm writing a simple JavaFX7 application where I display data pulled out of database using a StackedBarChart. I also provide the user with the ability to filter the displayed data sets based on a specific property's value. The problem that I'm facing is that there seems to be some caching issues. Consider the following scenario
Initial load, display everything to the user - no filtering involved.
Say our categories are named 1,2,3,4 and 5, and are rendered in that order (consider them sorted)
The user now selects a filter value. This leads to only categories 1,2,4 and 5 being on the screen (again, in that order - this is the expected behavior)
The user now resets the filter to "do-not-filter".
The expected output of step 3 would be 1,2,3,4 and 5, in that order. However, it is 1,2,4,5,3. Notice the category that got filtered out is added back at the end of the array instead of where it should be.
Things I've tried so far:
Assigning a new ObservableList via Axis.setCategory. this doesn't work.
Same as above, but also force the category list to null before hand.
Sorting the category list. This doesn't work either.
I can't (yet) update to Java 8 - I also can't just leave this as a broken feature because this is expected to roll out to users before we upgrade to Java 8. So JavaFX 8's FilteredList is out of question (and a backport is very much annoying just from looking at the changes to ObservableList). I also don't want to entirely recreate the graph if I can avoid it.
At this point, I'm out of ideas. Any suggestions are welcome. Below is the function that populates the chart.
private void refreshContents() {
this.vaguesTotal.getData().clear();
this.vaguesDone.getData().clear();
this.vaguesPending.getData().clear();
this.xAxis.setCategories(null);
this.chartCategories = FXCollections.observableArrayList();
// Already sorted here
for (VagueLight vagueInfo : context.getVagues()) {
if (this.categoryFilter != null && this.categoryFilter != vagueInfo.getCategory())
continue;
int dossiersTraites = vagueInfo.getNbDossiersTraites();
int dossiersPending = vagueInfo.getNbDossiersATraiter();
String vagueIdentifier = Integer.toString(vagueInfo.getId());
this.vaguesTotal.getData().add(new Data<String, Number>(vagueIdentifier, 0, vagueInfo));
this.vaguesDone.getData().add(new Data<String, Number>(vagueIdentifier, dossiersTraites, vagueInfo));
this.vaguesPending.getData().add(new Data<String, Number>(vagueIdentifier, dossiersPending, vagueInfo));
this.chartCategories.add(vagueIdentifier);
}
// This just sets up event handlers and styles for the series
for (Series<String, Number> dataSeries : this.barChart.getData()) {
for (Data<String, Number> dataNode : dataSeries.getData()) {
initializeDataNode(dataNode, dataSeries);
}
}
// This is where the "bug" happens
this.xAxis.setCategories(this.chartCategories);
layout(true);
}

How to set Record Selection Formula on Crystal Reports java

How do you create/set Record Selection Formula programatically on crystal reports using java? I tried searching on the internet but the only option is through IFilter which requires a Crystal Report Server. My program only uses the JRC library. Also this is a java desktop application using swing.
It may be a bit late, but maybe this is useful for someone:
reportClientDoc.getDataDefController().getRecordFilterController().setFormulaText("your record selection formula here");
I was doing some research about this and noticed that there are 3 methods with which you can do this:
Using the IFilter interface as shown in this example provided by SAP
// Set the filter string to be used as the Record Filter
String freeEditingFilter = "{Customer.Country} = 'Canada'";
// Retrieve the record filter for the Data Definition Controller
IFilter iFilter = clientDoc.getDataDefController().getDataDefinition().getRecordFilter();
// Set the filter to free editing text filter string
iFilter.setFreeEditingText(freeEditingFilter);
// Modify the filter through the Record Filter Controller to the report
clientDoc.getDataDefController().getRecordFilterController().modify(iFilter);
I am using the JRC only without a Crystal Report Server and the above example worked for me.
As Francisco said in his answer, using the setFormulaText method:
clientDoc.getDataDefController().getRecordFilterController().setFormulaText("{Customer.Country} = 'Canada'");
Using parameters. Parameters can be passed to the report using code (you can use the addDiscreteParameterValue function in the helper class) or else they can be filled in by the user during runtime. I chose not to opt for this option because they can not be set to optional
If you want to create a crystal report of your program, you need another jar file of software.
You can create your program in NetBeans IDE and link your IDE with IReport software which is used in NetBeans for creating Reporting in java.
You get many example from internet about this.

jface databinding for javascript

I'm a java developer. I use SWT and JFace databinding in most projects. Recently, I've been task to work on a different kind of project involving PHP. I need to develop a web application using PHP on server side and JavaScript on client side. So far, I'm strutting with jQuery to do all the work. jQuery is nice, but not nice enough to provide all the plumbing required to build the web interface quickly.
In desktop application, JFace databinding provide all the features to bind widgets, form, labels to the model allowing you to sync the content of a form to an object, validate the content of the form and provide feedback if the content is ok or not.
e.g.: For a text field, you may bind the text value to the property of an object. Add a validation to check if the text value is empty. When empty, show a tool tips asking the user to enter a value and disable the submit button.
So I'm aksing you, is there anything similar to JFace Databinding for JavaScript ?
http://visualstudiomagazine.com/articles/2012/02/01/2-great-javascript-data-binding-libraries.aspx
http://uberpwn.wordpress.com/2010/10/10/databinding-js-objects-into-html-forms-with-jquery-datalink-and-jquery-tmpl/
http://blogs.claritycon.com/blog/2011/02/mvvm-databinding-javascript-with-knockout-html5-boilerplate/
Right now the modern components that support databinding are angular, aurelia and react (sort of... +redux that is about to be dead).
jQuery doesn't provide nice databinding implementation. It needs to manually wire up all prop changes. Probably implement some Observer/Subscriber approach.
Or use some component for databinding tasks that provides enough convenient databinding definition commands. I did it with databindjs. e.g.
// Lets assume that there is just simple form (target)
var simpleForm = {
input: $('.simple .input-value'),
output: $('.simple .output-value')
};
// And here is the simple model object (source)
var model = {
text: 'initial value'
};
// Lets set two directional binding between [input] <-> [text]
var simpleBinding = bindTo(simpleForm, () => model, {
'input.val': 'text', // bind to user input
'output.text': 'text' // simple region that will react on user input
});
// This command will sync values from source to target (from model to view)
updateLayout(simpleBinding);
subscribeToChange(simpleBinding, () => {
$('.simple .console').html(JSON.stringify(model));
});
// Just initialize console from default model state
$('.simple .console').html(JSON.stringify(model));
The full solution here

Is it possible for a column to become a hyperlink using google charts API?

I am using Visualr http://googlevisualr.herokuapp.com/ with Rails and having a good amount of success creating dynamic charts. However, I am wondering if it's possible to allow the user to click on the column in a 'column chart' and be linked to a page? I am happy to know the java version if you aren't familiar with visualr.
Thanks!
It now is available!
There has recently been an update on this issue. Therefore I want to update this SO Q&A.
Resources:
Google Visualr Github Pull Request #39
Google Visualr Github Issue #36
Code example
xxx_controller.rb
#table = GoogleVisualr::Interactive::ColumnChart.new(g, options_g)
#table.add_listener("select", "function(e) {
EventHandler(e, chart, data_table)
}")
And then in a JS file e.g. app/assets/javascripts/application.js:
function EventHandler(e, chart, data) {
var selection = chart.getSelection();
if (selection.length > 0) {
var row = selection[0].row;
var department = data.getValue(row, 0);
alert(department + " | " + row)
}
}
Google Charts (whether you access them directly or via a wrapper gem like Visualr) are simple images, so the straight answer is "No", at least not without doing some work of your own. In order to achieve this you would need to place your own transparent clickable links (or divs or whatever) over the image, in the right place, to correspond to the columns that google generate in the image.
I'd imagine this would be tricky and error prone - it might actually be easier for you to just generate the columns yourself in html and css, using the data you would previously have sent to google to set the height (in %) of the columns. Then, each column would be a seperate html element and could link to whatever you want.
So, more control = more work. As usual :)

Categories

Resources