ControlsFx - Spreadsheetview - DateCell - keep editing on failure - spreadsheet

we use a spreadsheetview with different kind of cell types.
In the documentation to SpreadsheetCellEditor we found the following text:
The policy regarding validation of a given value is defined in
SpreadsheetCellType.match(Object). If the value doesn't meet the requirements
when saving the cell, nothing happens and the editor keeps editing.
now we facing the following problem:
if you enter "abcd" in an integer cell as a wrong entry and push enter key, nothing happens. Editor is still in edit mode. This is exactly the behaviour as descripted in the documentation. that is what we want.
if you have a date cell and enter a wrong date or something else and push enter key, cell stops editing mode and set value return to "old" value.
how can we prevent this behaviour?
Maybe its a bug in the Date SpreadsheetCellType?
we use a lot of custom cellType Classes, but the behaviour is also comprehensibly with this little example.
I hope everything is well explained.
Thanks for your help.
import java.time.LocalDate;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.controlsfx.control.spreadsheet.GridBase;
import org.controlsfx.control.spreadsheet.SpreadsheetCell;
import org.controlsfx.control.spreadsheet.SpreadsheetCellType;
import org.controlsfx.control.spreadsheet.SpreadsheetView;
public class SpreadSheetExample extends Application {
private SpreadsheetView getSpreadSheet() {
SpreadsheetView spreadSheetView;
GridBase grid;
grid = new GridBase(10, 2);
spreadSheetView = new SpreadsheetView(grid);
ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
for (int row = 0; row < grid.getRowCount(); ++row) {
final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
for (int column = 0; column < grid.getColumnCount(); ++column) {
if (column < 1) {
list.add(SpreadsheetCellType.DATE.createCell(row, column, 1, 1, LocalDate.now()));
} else {
list.add(SpreadsheetCellType.INTEGER.createCell(row, column, 1, 1, column));
}
}
rows.add(list);
}
spreadSheetView.getColumns().forEach((column) -> {
column.setPrefWidth(280);
});
grid.setRows(rows);
return spreadSheetView;
}
#Override
public void start(Stage primaryStage) {
StackPane root = new StackPane();
root.getChildren().add(getSpreadSheet());
Scene scene = new Scene(root, 800, 400);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Update:
are there no controlsfx experts?
Solved:
https://groups.google.com/forum/#!topic/controlsfx-dev/ro7-MvLFD1A

It is solved.
i got some help from one of the major contributor of ControlsFX.
The documentation was a bit unclearly.
In order to get the described behavior, a custom Cell Type + Editor based on the existing ones can be created.
For all details take a look in this thread:
https://groups.google.com/forum/#!topic/controlsfx-dev/ro7-MvLFD1A

Related

How To Automate Slider in Selenium Java

Hi I am trying to automate https://emicalculator.net/
.I tried many approach but did not get success Below is my code for automating Interest rate slider
package seleniumBasics;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class AdjustSliderValue {
static String baseUrl = "https://emicalculator.net/";
public static WebDriver driver;
#BeforeTest
public WebDriver createDriver() {
driver = DriverSetup.getWebDriver();
driver.get(baseUrl);
return driver;
}
#AfterMethod
public void CloseDriver() {
driver.quit();
}
public static int GetPixelsToMove(WebElement Slider, double Amount, double SliderMax, double SliderMin) {
int pixels = 0;
int tempPixels = Slider.getSize().getWidth();
System.out.println(tempPixels);
tempPixels = (int)(tempPixels / (SliderMax - SliderMin));
System.out.println(tempPixels);
tempPixels = (int) (tempPixels * (Amount - SliderMin));
System.out.println(tempPixels);
pixels = tempPixels;
return pixels;
}
#Test
public static void verifySlider() throws InterruptedException {
WebElement Slider = driver.findElement(By.xpath("//*[#id=\"loaninterestslider\"]"));
int PixelsToMove = GetPixelsToMove(Slider, 15, 20, 5);
Actions SliderAction = new Actions(driver);
SliderAction.clickAndHold(Slider).moveByOffset((-(int) Slider.getSize().getWidth() / 2), 0)
.moveByOffset(PixelsToMove, 0).release().perform();
}
}
I want a method which can automate any slider. Could any one who knows please help me. Thanks in advance.
You may also try Key actions using Send Keys
// Set Loop counter to get desired value
<Your_Slider_Element>.sendKeys(Keys.ARROW_LEFT); // Or ARROW_RIGHT
// End loop
dragAndDropBy usually work best with slider. Make sure the way you calculate pixel is correct then it good to go.
driver.get("https://emicalculator.net/");
WebElement Slider = driver.findElement(By.xpath("//*[#id=\"loaninterestslider\"]"));
int PixelsToMove = GetPixelsToMove(Slider, 15, 20, 5);
Actions move = new Actions(driver);
Action action = (Action) move.dragAndDropBy(Slider, PixelsToMove, 0).build();
action.perform();
Import package
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
Sliderwidth is basically just 100% of the size here but you can add whatever pixel you want.
driver.get("https://emicalculator.net/");
WebElement Slider = driver.findElement(By.xpath("//*[#id=\"loaninterestslider\"]"));
Dimension sliderSize = Slider.getSize();
int sliderWidth = sliderSize.getWidth();
int xCoord = Slider.getLocation().getX();
Actions builder = new Actions(driver);
builder.moveToElement(Slider)
.click()
.dragAndDropBy
(Slider,xCoord + sliderWidth, 0)
.build()
.perform();
Import
import org.openqa.selenium.Dimension;
import org.openqa.selenium.interactions.Actions;
WebDriver driver = new ChromeDriver();
driver.get("https://emicalculator.net/");
WebElement a = driver.findElement(By.cssSelector("#loanamountslider span"));
Actions action = new Actions(driver);
action.clickAndHold(a).moveByOffset(500, 0).perform();
Here you go , you have to click the slider element and drag it
As the topicstarter correctly mentioned, the question is about how to automate any slider. So let me extend existing answers with requested solution.
The solution is not new - Selenium already has sample with Select. Let's build similar solution.
So assume we wanted to have some object of type EmiSlider so we could use it the way:
...
EmiSlider slider = new EmiSlider(driver.findElement(By.id("loanamountslider")));
slider.slide(100);
...
We are explicitly mentioning the desired locator and passing into constructor of class EmiSlider. The EmiSlider class then would be:
public class EmiSlider {
private final WebElement sliderRoot;
private final WebDriver driver;
public EmiSlider(WebElement slider) {
// Simply store passed root WebElement
this.sliderRoot = slider;
// We require driver instance for internal use so resolve it and store
this.driver = ((WrapsDriver) slider).getWrappedDriver();
}
/**
* Moves slider left or right
* #param x pixels to move slider by. Positive value moves right, negative - left
*/
public void slide(int x) {
// Find the slider WebElement, which is child of root element, using relative search
WebElement sliderElement = this.sliderRoot.findElement(By.cssSelector("span"));
// Perform slide action
new Actions(this.driver)
.clickAndHold(sliderElement)
.moveByOffset(x, 0)
.release()
.perform();
}
}
The current slider implementation had few drawbacks:
It does not count on the current and extreme positions
Different sliders might have different scales (and they do)
The amout inputs are left alone while
Hope one can add missed functionality

Sonar Custom Widget

I created a widget using the source code available in github. Now I'm using that widget in SonarQube V5.3. This is where I got the source code from:
https://github.com/SonarSource/sonar-examples/tree/master/plugins/sonar-reference-plugin
When I use this widget it is showing up the same data across multiple projects. I would like to know if there is any way I can display different data for different projects. Please share your ideas. Below is the code that displays the ruby widget
import org.sonar.api.web.AbstractRubyTemplate;
import org.sonar.api.web.Description;
import org.sonar.api.web.RubyRailsWidget;
import org.sonar.api.web.UserRole;
import org.sonar.api.web.WidgetCategory;
import org.sonar.api.web.WidgetProperties;
import org.sonar.api.web.WidgetProperty;
import org.sonar.api.web.WidgetPropertyType;
import org.sonar.api.batch.CheckProject;
import org.sonar.api.resources.Project;
#UserRole(UserRole.USER)
#Description("Sample")
#WidgetCategory("Sample")
#WidgetProperties({
#WidgetProperty(key = "Index",type=WidgetPropertyType.TEXT
),
})
public class OneMoreRubyWidget extends AbstractRubyTemplate implements RubyRailsWidget {
#Override
public String getId() {
return "Sample";
}
#Override
public String getTitle() {
return "Sample";
}
#Override
protected String getTemplatePath() {
return "/example/Index.html.erb";
}
}
Thank you so much in advance
You haven't specified global scope for your widget (#WidgetScope("GLOBAL")) in the .java file, so this is a question of what's in your .erb file.
This Widget Lab property widget should give you some pointers. Specifically: you want to pick up #project in your widget, and query with #project.uuid. Here's another project-level widget for comparison.
You should be aware, though, that SonarSource is actively working to remove Ruby from the platform, so at some future date, you'll probably end up re-writing your widgets (likely in pure JavaScript).

adding dynamic data to MPAndroidChart

Can anyone explain with a simple example on how to add the data dynamically to the chart which is already drawn. I tried with the details in the github link to add the data, but couldn't do so. A very short example or link is also fine. Thanks
You can download the project here https://github.com/PhilJay/MPAndroidChart/archive/master.zip
Open the project, and in MPChartExample, you have the file DynamicalAddingActivity.java.
You need to create the chart:
Add dataSet (your line(s)) with the values (please view the example in
addDataSet() method in MPChartExample project).
After you can do a CountTimerDown that add a new Entry, for the
dataset.
/** each 5 seconds **/
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
double randomValue = 19.0 + (Math.random() * (21.0 - 19.0));
int indexOfMyLine = 0;
Entry newEntry = new Entry((float) randomValue, indexOfMyLine);
}
}.start();

Sorting an ArrayList of NotesDocuments using a CustomComparator

I'm trying to sort a Documents Collection using a java.util.ArrayList.
var myarraylist:java.util.ArrayList = new java.util.ArrayList()
var doc:NotesDocument = docs.getFirstDocument();
while (doc != null) {
myarraylist.add(doc)
doc = docs.getNextDocument(doc);
}
The reason I'm trying with ArrayList and not with TreeMaps or HashMaps is because the field I need for sorting is not unique; which is a limitation for those two objects (I can't create my own key).
The problem I'm facing is calling CustomComparator:
Here how I'm trying to sort my arraylist:
java.util.Collections.sort(myarraylist, new CustomComparator());
Here my class:
import java.util.Comparator;
import lotus.notes.NotesException;
public class CustomComparator implements Comparator<lotus.notes.Document>{
public int compare(lotus.notes.Document doc1, lotus.notes.Document doc2) {
try {
System.out.println("Here");
System.out.println(doc1.getItemValueString("Form"));
return doc1.getItemValueString("Ranking").compareTo(doc2.getItemValueString("Ranking"));
} catch (NotesException e) {
e.printStackTrace();
}
return 0;
}
}
Error:
Script interpreter error, line=44, col=23: Error calling method
'sort(java.util.ArrayList, com.myjavacode.CustomComparator)' on java
class 'java.util.Collections'
Any help will be appreciated.
I tried to run your SSJS code in a try-catch block, printing the error in exception in catch block and I got the following message - java.lang.ClassCastException: lotus.domino.local.Document incompatible with lotus.notes.Document
I think you have got incorrect fully qualified class names of Document and NotesException. They should be lotus.domino.Document and lotus.domino.NotesException respectively.
Here the SSJS from RepeatControl:
var docs:NotesDocumentCollection = database.search(query, null, 0);
var myarraylist:java.util.ArrayList = new java.util.ArrayList()
var doc:NotesDocument = docs.getFirstDocument();
while (doc != null) {
myarraylist.add(doc)
doc = docs.getNextDocument(doc);
}
java.util.Collections.sort(myarraylist, new com.mycode.CustomComparator());
return myarraylist;
Here my class:
package com.mycode;
import java.util.Comparator;
public class CustomComparator implements Comparator<lotus.domino.Document>{
public int compare(lotus.domino.Document doc1, lotus.domino.Document doc2) {
try {
// Numeric comparison
Double num1 = doc1.getItemValueDouble("Ranking");
Double num2 = doc2.getItemValueDouble("Ranking");
return num1.compareTo(num2);
// String comparison
// return doc1.getItemValueString("Description").compareTo(doc2.getItemValueString("Description"));
} catch (lotus.domino.NotesException e) {
e.printStackTrace();
}
return 0;
}
}
Not that this answer is necessarily the best practice for you, but the last time I tried to do the same thing, I realized I could instead grab the documents as a NotesViewEntryCollection, via SSJS:
var col:NotesViewEntryCollection = database.getView("myView").getAllEntriesByKey(mtgUnidVal)
instead of a NotesDocumentCollection. I just ran through each entry, grabbed the UNIDs for those that met my criteria, added to a java.util.ArrayList(), then sent onward to its destination. I was already sorting the documents for display elsewhere, using a categorized column by parent UNID, so this is probably what I should have done first; still on leading edge of the XPages/Notes learning curve, so every day brings something new.
Again, if your collection is not equatable to a piece of a Notes View, sorry, but for those with an available simple approach, KISS. I remind myself frequently.

Java3D and Behaviours : KeyNavigatorBehaviour works fine, but not MouseRotate

I don't manage to give user mouse interaction to a ColorCube by using a MouseRotate. However, when i use a KeyNavigatorBehaviour, i can control the cube with keyboard as needed.
Here the code i used to test MouseRotate :
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JFrame;
import javax.vecmath.Point3d;
import com.sun.j3d.exp.swing.JCanvas3D;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class MovingAroundCube extends JFrame {
private static final long serialVersionUID = 1L;
public MovingAroundCube(){
setTitle("Moving around cube");
setSize(300,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
JCanvas3D jCanvas3D = new JCanvas3D(new GraphicsConfigTemplate3D());
jCanvas3D.setSize(300, 300);
add(jCanvas3D);
SimpleUniverse universe = new SimpleUniverse(jCanvas3D.getOffscreenCanvas3D());
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(createSceneGraph());
}
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
TransformGroup listenerGroup = new TransformGroup();
listenerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
listenerGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRoot.addChild(listenerGroup);
//KeyNavigatorBehavior behaviour = new KeyNavigatorBehavior(listenerGroup);
MouseRotate behaviour = new MouseRotate(listenerGroup);
behaviour.setSchedulingBounds(new BoundingSphere(new Point3d(), 100));
listenerGroup.addChild(behaviour);
listenerGroup.addChild(new ColorCube(0.4));
return objRoot;
}
public static void main(String[] args) {
new MovingAroundCube().setVisible(true);
}
}
If I uncomment the line creating the KeyNavigatorBehaviour and comment the line creating the MouseRotate, user interaction this time is possible .
So, why can't the cube react to the mouse (when i use MouseRotate behaviour instance) ?
Any help will be appreciated.
System : Xubuntu 11.04
Java3D version : 1.5.2
There are two ways to solve this dilemma:
Use this constructor:
MouseRotate behaviour = new MouseRotate(jCanvas3D, listenerGroup);
or
Enable mouse events as long as no MouseListeners are added:
import java.awt.AWTEvent;
JCanvas3D jCanvas3D = new JCanvas3D(new GraphicsConfigTemplate3D()) {
{
this.enableEvents(AWTEvent.MOUSE_EVENT_MASK |
AWTEvent.MOUSE_MOTION_EVENT_MASK |
AWTEvent.MOUSE_WHEEL_EVENT_MASK);
}
};
Key events are enabled because 'setFocusable(true)' is set in JCanvas3D.
August, InteractiveMesh