I'm trying to create a calendar using MATLAB GUI.
I found this tutorial and created calendar:
com.mathworks.mwswing.MJUtilities.initJIDE;
% Put calendar to my figure
jPanel = com.jidesoft.combobox.DateChooserPanel;
[hPanel,hContainer] = javacomponent(jPanel,[500,130,200,200],gcf);
set(handles.hPanel, 'MousePressedCallback', ...
#(src, evnt)CellSelectionCallback(src, evnt, handles));
set(handles.hPanel, 'KeyPressedCallback', ...
#(src, evnt)CellSelectionCallback(src, evnt, handles));
Also I have Edit Text object. Lets try to put Selected Value to it!
I use excaza's code:
function CellSelectionCallback(hObject, evnt, handles)
hModel = handle(hObject.getSelectionModel, 'CallbackProperties');
selectedDate = hModel.getSelectedDate();
dayNumber = get(selectedDate,'Date');
handles.edit_start.String = num2str(dayNumber);
handles.newNote(3) = {dayNumber};
guidata(handles.figure1, handles);
So I can read selected date and put it anywhere.
Problem
Code works only in Debug Mode. In normal mode my Edit Text Object (edit_start) stays empty!
Related
I have a transition screen from which I am getting values(s) via a checkbox control, I need to get these values and update them on another checkbox control in the issues view screen. The below code updates the values but doesn't change the checkbox to checked.
platvalue = issue.getCustomFieldValue(platRelOnField) //platRelOnField is the field from where I am getting my values to be set , it has 3 options [High,Low,Medium]
ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(platRelOnAPIField),platvalue);
platRelOnAPIField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());
I am new to groovy/jira and cant seem to know the right way to set the checkbox options properly.
Any help in the right direction is appreciated.
I am using JIRA 6.3.9
Managed to get it working by writing the below code
ArrayList<LazyLoadedOption> optionsList = new ArrayList<LazyLoadedOption>();
FieldConfig fieldConfig = platRelOnAPIField.getRelevantConfig(issue);
OptionsManager optionManager = ComponentAccessor.getOptionsManager();
platOptions = optionManager.getOptions(fieldConfig);
for(def i = 0;i<platOptions.size();i++){
def optVal = platOptions.get(i).getValue();
if(platOptions.get(i).getValue().equals("custom field value")){
optionsList.add(platOptions.get(i));
break;
}
}
platRelOnAPIField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(platRelOnAPIField), optionsList),changeHolder)
I'm doing an integration testing with DBUnit (2.49) + Hibernate (4.1.3) following this tutorial.
Production database : Oracle 10
Test database : Hsqldb 2.3.3
Context
My data contains the current format of date : yyyy/MM/dd. However,according to DBUnit faq, DBUnit only supports this format yyyy-mm-dd hh:mm:ss.fffffffff, so I had to create a new format for TimeStamp.
How I tried to fix it
I created a CustomTimeStampDataType based on this tutorial. I changed this part:
String formats[] = {"yyyy-MM-dd HH:mm", "yyyy-MM-dd HH:mm a", "yyyy-MM-dd HH:mm:ss.fffffffff"};
into this one:
String formats[] = {"yyyy/MM/dd"};
I created a CustomeDataTypeFactory following the same tutorial. I only make it extend Oracle10DataTypeFactory rather than DefaultDatatTypeFactory.
In HibernateDBUnitTestCase, I override setDatabaseConfig() with the following:
#Override
protected void setUpDatabaseConfig(DatabaseConfig config){
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new CustomDataTypeFactory());
}
But I got new errors
I ran a unit test and got this error.
org.dbunit.dataset.datatype.TypeCastException: Unable to typecast value <1997/02/14> of type <java.lang.String> to TIMESTAMP
at org.dbunit.dataset.datatype.TimestampDataType.typeCast(TimestampDataType.java:120)
at org.dbunit.dataset.datatype.TimestampDataType.setSqlValue(TimestampDataType.java:176)
at org.dbunit.database.statement.SimplePreparedStatement.addValue(SimplePreparedStatement.java:73)
at org.dbunit.operation.RefreshOperation$RowOperation.execute(RefreshOperation.java:189)
at org.dbunit.operation.RefreshOperation.execute(RefreshOperation.java:113)
at org.dbunit.AbstractDatabaseTester.executeOperation(AbstractDatabaseTester.java:190)
at org.dbunit.AbstractDatabaseTester.onSetup(AbstractDatabaseTester.java:103)
at org.dbunit.DatabaseTestCase.setUp(DatabaseTestCase.java:156)
at test.HibernateDbUnitTestCase.setUp(HibernateDbUnitTestCase.java:85)
at test.PlayerTest.setUp(PlayerTest.java:117)
Caused by: java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
at java.sql.Timestamp.valueOf(Unknown Source)
at org.dbunit.dataset.datatype.TimestampDataType.typeCast(TimestampDataType.java:116)
... 20 more
That was weird, it seemed like my CustomTimeStamp was not called, so I changed the date in the dataset using the default format : 1997-02-14 00:00:00.0, and ran the unit test again. Then I got:
org.dbunit.dataset.datatype.TypeCastException: Unable to typecast value <1997-02-14 00:00:00.0> of type <java.lang.String> to TIMESTAMP
at test.CustomTimestampDataType.typeCast(CustomTimestampDataType.java:69)
at test.CustomTimestampDataType.setSqlValue(CustomTimestampDataType.java:84)
at org.dbunit.database.statement.SimplePreparedStatement.addValue(SimplePreparedStatement.java:73)
at org.dbunit.operation.RefreshOperation$RowOperation.execute(RefreshOperation.java:189)
at org.dbunit.operation.RefreshOperation.execute(RefreshOperation.java:113)
at org.dbunit.AbstractDatabaseTester.executeOperation(AbstractDatabaseTester.java:190)
at org.dbunit.AbstractDatabaseTester.onSetup(AbstractDatabaseTester.java:103)
at org.dbunit.DatabaseTestCase.setUp(DatabaseTestCase.java:156)
at test.HibernateDbUnitTestCase.setUp(HibernateDbUnitTestCase.java:85)
at test.PlayerTest.setUp(PlayerTest.java:117)
That means CustomTimeStamp was actually called. Seems like, the problem stemed from DatabaseTestCase.setUp which somehow called the wrong TimeStampDataType.
How could I fix this issue?
My first option was to replace every yyyy/MM/dd into yyyy-mm-dd in the dataset using regular expressions. This worked fine, until I had to test a method that selected a date based on a request (so the format is yyyy-mm-dd) and compared it to the current date. ( so the format is yyyy / mm / dd). Hsqldb can't compare two dates with different format.
My second option was to decompile dbunit.jar, rewrite TimeStampDataType based on the tutorial. I'm unfamiliar with bytecode writing so before entering uncharted waters, I wanted to know if you had another solution.
Thank you in advance
Fixed it!
So I ended up using my second option.
This is the detailed path for those who need it.
Download dbUnit.2.2.source.jar
Unzip the jar
Go to Eclipse, File > New > Java Project
Uncheck "Use default location"
In Location : specify the path to the new folder created from the jar
Click on Finish
Modify the TimestampDataType.java (if needed)
Instead of ts = java.sql.Timestamp.valueOf(stringValue); use the code below
String formats[] =
{"dd/MM/yyyy HH:mm:ss.SS"}; //and more depending on your need
Timestamp ts = null;
for (int i = 0; i < formats.length; i++)
{
SimpleDateFormat sdf = new SimpleDateFormat(formats[i]);
try {
java.util.Date date = sdf.parse(stringValue);
ts = new Timestamp(date.getTime());
return ts;
}
catch( ParseException e) {
}
Modify the DateDataType.java (if needed)
Instead of return java.sql.Date.valueOf(stringValue); , use the code below
String formats[] =
{"dd/MM/yyyy"}; //and more depending on your need
for (int i = 0; i < formats.length; i++)
{
SimpleDateFormat sdf = new SimpleDateFormat(formats[i]);
try {
java.util.Date date = sdf.parse(stringValue);
java.sql.Date datesql = new java.sql.Date(date.getTime());
return datesql;
}
catch( ParseException e) {
}
}
Right-click on your project, then Export
Select JAR file, then Next
Fill the export destination then Finish.
You just have to add this new jar to the library to make it work.
I am designing a staff data manager which will allow the users to add, edit and view the staff details.
In the code I have a JFormattedTextField defined as follows.
SimpleDateFormat dateDOB = new SimpleDateFormat("dd/MM/yyyy");
JFormattedTextField DOBBX = new JFormattedTextField(dateDOB);
When I want to edit the staff data, I load the date to the JFormattedTextField as follows:
DOBBX.setText(""+retrievedStaff.getDOB());
After editing if I save the data, the value for DOB is null and I get a java.lang.NullPointerException. This only happens if I leave the value for DOB unedited. If I make changes to DOB or enter it again then DOB value is correctly saved.
Also if I add a new staff and then try to edit the staff data without closing the program, the date is properly saved to the binary file with no nullpointer error.
How do I fix this?
(I have no idea how to provide an MCVE for this as my code is quite long and consists of many classes)
Before saving the date to binary file I use the following method to convert it to a string:
public String getDOB() {
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
try{
String textDate = df.format((DOB));
return textDate;
}catch(Exception e){e.printStackTrace();}
return null;
}
In the StackTrace it is mentioned that the error is produced by this part of the code:
String textDate = df.format((DOB));
I solved this problem. So as I told in the question that the date is properly saved to binary file if I click or change the DOB textbox. So I set the cursor to DOB textfield when the user clicks edit button using requestFocus().
I am using Web driver 2.31 with Java. It seems the web driver is unable to perform click action on an input element having onclick() attribute.
The input element I need to perform click action on is having the following attributes - id (which is a random generated number), class, type=button, onclick, onmouseout, onmouseover, title and value.
I'm able to fetch the values of title and value attributes which means that the web driver is able to recognize the input element but is not able to perform click action on it.
I have tried with the following:
webdriver.findElement(By.xpath("xpath for the input")).click()
webdriver.findElement(By.xpath("xpath for the input")).sendKeys(Keys.ENTER);
new Actions(webdriver).moveToElement(webdriver.findElement(By.xpath("xpath for the input"))).click().perform();
None of the above options are working.
Do you get any exceptions from element.click()? It it enabled and visible? One of the problems we had was that WebDriver didn't handle position:static elements correctly, so during playback it would cover the button (and you won't see it on screenshot) and it would throw exception "Element is not clickable at point".
We had similar problem with element and had following code that did work sometimes (but also not 100% of times):
element.click();
if("button".equals(tagName)) {
if(element.isEnabled() && element.isDisplayed())
element.sendKeys(Keys.ENTER);
}
But the problem disappeared itself after upgrading WebDriver and we removed sendKeys(ENTER), also it was working fine in 2.29.0.
I faced exactly same problem in my project. The issue was not to locate the element but the onClick() event was not firing.
Then i found out that something else was there which stopped from the event to fire. I had used java script to enable the date picker box & did this,
((JavascriptExecutor)driver).executeScript ("document.getElementById('txtOriginDate').removeAttribute('readonly',0);");
WebElement originDateBox= driver.findElement(By.xpath(prop.getProperty("originDateBox")));
originDateBox.clear();
originDateBox.sendKeys("9-Dec-2014"); //Enter date
Developer designed this in such a way that if you don't use date picker to select date, a specific variable was not set. Which eventually made the **onclick event not to fire.
The date picker code was something like this,
var jsoncustdate = "";
var jsonorigindate = "";
function onSelectCalender( StrDt, obj )
{
if ( !varReadonly ) {
if ( $( "#txtCustDescisionDate" ).attr( "IsDisable" ) == "FALSE" )
{
if ( obj.id == "txtCustDescisionDate" )
{
custobjDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay, 0, 0, 0, 0 );
jsoncustdate = custobjDt.getTime();
jsoncustdate = "\/Date(" + jsoncustdate + ")\/";
DisabledBtnStage();
// $("#txtFromDate").datepicker("option", "maxDate", objDt);
}
if ( obj.id == "txtOriginDate" )
{
var objDt = new Date( obj.selectedYear, obj.selectedMonth,obj.selectedDay,0, 0,0,0 );
jsonorigindate = objDt.getTime();
jsonorigindate = "\/Date(" + jsonorigindate + ")\/";
DisabledBtnStage();
// $("#txtToDate").datepicker("option", "minDate", objDt);
}
}
elogCommon.CheckMandatory();
}
}
I finally used date picker in normal way & the event fired smoothly.
I hope this answer will help . .cheers !!!
I'm writing a visio export and created a visio template file containing custom line endings. When I try to set those using code, it is not working.
//Create two shapes
final IVMaster lApp = stencilObj.masters("Application");
IVShape shapeFrom = pagObj.drop(lApp, 1, 1);
IVShape shapeTo = pagObj.drop(lApp, 2, 3);
//Connect the shapes
final IVMaster connMaster = stencilObj.masters("Connection");
IVShape connection = pagObj.drop(connMaster, 2, 3);
final IVCell gluefrom1 = connection.cells("BeginX");
final IVCell glueat1 = shapeFrom.cells("PinX");
gluefrom1.glueTo(glueat1);
final IVCell gluefrom2 = connection.cells("EndX");
final IVCell glueat2 = shapeTo.cells("PinX");
gluefrom2.glueTo(glueat2);
//Set arrow ending
connection.cellsU("EndArrow").formulaForceU(new Integer(46).toString());
So there are 45 default line endings in visio and the 46th in the list is mine. When I'm setting number 45 it works, number 46 doesn't.
When I right click on the connection and go to Format->Line, the correct line ending is selected and the Preview is also correct. I have to select the ending again and click apply for it to be updated in the document.
I'm working with Visio 2007
Ok I found the problem. You need to use the full name for the line ending and call a visio function with it.
//Set arrow ending
connection.cellsU("EndArrow").formula("=USE(\"46: interface_in\")");