Skip to content

Commit

Permalink
fix formatting in new files
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolaos Pringouris <nprigour@gmail.com>
  • Loading branch information
nprigour committed Apr 15, 2018
1 parent 59c9319 commit cc16ca6
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,44 +35,44 @@ public class DateTimeCellEditorTest {

@Before
public void setUp() throws Exception {
shell=new Shell(Display.getCurrent());
shell = new Shell(Display.getCurrent());
}

@After
public void tearDown() throws Exception {
shell.dispose();
}

@Test
public void testDoGetValue() {
DateTimeCellEditor editor;
editor = new DateTimeCellEditor(shell);

DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
String dateString ="12/12/2022 23:00:00";
String dateString = "12/12/2022 23:00:00";
try {
Date time = format.parse(dateString);
editor.setValue(time);
assertEquals(time.getTime(), ((Date)editor.getValue()).getTime() );
assertEquals(time.getTime(), ((Date) editor.getValue()).getTime());
} catch (ParseException e) {
e.printStackTrace();
}

editor.setValue("");
assertEquals( null, editor.getValue() );
assertEquals(null, editor.getValue());

}

@Test
public void testIsValidCall() throws Exception {
DateTimeCellEditor editor;
editor = new DateTimeCellEditor(shell);
//empty string

// empty string
editor.setValue("");
assertFalse(editor.isValueValid());
//empty string

// empty string
editor.setValue(null);
assertTrue(editor.isValueValid());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public class NumberCellEditorTest {

@Before
public void setUp() throws Exception {
shell=new Shell(Display.getCurrent());
shell = new Shell(Display.getCurrent());
}

@After
public void tearDown() throws Exception {
shell.dispose();
}

@Test
public void testShort() throws Exception {
runTest(Short.valueOf((short) 2), Short.valueOf((short) 3), Short.class);
Expand All @@ -55,80 +55,80 @@ public void testInteger() throws Exception {

@Test
public void testLong() throws Exception {
runTest(Long.valueOf(2l), Long.valueOf(3l), Long.class);
runTest(Long.valueOf(2l), Long.valueOf(3l), Long.class);
}

@Test
public void testDouble() throws Exception {
runTest(Double.valueOf(2), Double.valueOf(3), Double.class);
runTest(Double.valueOf(2), Double.valueOf(3), Double.class);
}

@Test
public void testFloat() throws Exception {
runTest(Float.valueOf(2), Float.valueOf(3), Float.class);
runTest(Float.valueOf(2), Float.valueOf(3), Float.class);
}

@Test
public void testBigDecimal() throws Exception {
runTest(BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.class);
runTest(BigDecimal.valueOf(2), BigDecimal.valueOf(3), BigDecimal.class);
}

@Test
public void testBigInteger() throws Exception {
runTest(BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.class);
runTest(BigInteger.valueOf(2), BigInteger.valueOf(3), BigInteger.class);
}

@Test
public void testNull() throws Exception {
runTest(null, Integer.valueOf(3), Integer.class);
runTest(null, Integer.valueOf(3), Integer.class);
}

@Test
public void testEmptyEqualsNull() throws Exception {
NumberCellEditor editor;
editor = new NumberCellEditor(shell, Integer.class);
editor.setValue("");
assertNull(editor.getValue() );
assertNull(editor.getValue());
}

@Test(expected = NumberFormatException.class)
public void testWrongFormatNumber() throws Exception {
NumberCellEditor editor;
editor = new NumberCellEditor(shell, Integer.class);
//empty string
editor = new NumberCellEditor(shell, Integer.class);

// empty string
editor.getValue();
assertNull(editor.getValue() );
//not parsable number
assertNull(editor.getValue());

// not parsable number
editor.setValue("aa");
editor.getValue();
assertNull(editor.getValue() );
assertNull(editor.getValue());
}

@Test
public void testIsValidCall() throws Exception {
NumberCellEditor editor;
editor = new NumberCellEditor(shell, Integer.class);
//empty string
editor = new NumberCellEditor(shell, Integer.class);

// empty string
editor.setValue("aa");
assertFalse(editor.isValueValid());
//empty string

// empty string
editor.setValue("");
assertTrue(editor.isValueValid());
}
private void runTest( Object value, Object value2, Class<? extends Number> class1 ) {

private void runTest(Object value, Object value2, Class<? extends Number> class1) {
NumberCellEditor editor;
editor = new NumberCellEditor(shell, class1);

editor.setValue(value);
assertEquals( value, editor.getValue() );
assertEquals(value, editor.getValue());

editor.setValue(value2);
assertEquals( value2, editor.getValue() );
assertEquals(value2, editor.getValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
package org.locationtech.udig.ui;


import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand All @@ -22,9 +21,9 @@
import org.eclipse.swt.widgets.Control;

/**
* Class represents a special cell editor which will open a calendar/date
* dialog in which a date and time can be selected.
* The class can return a java.util.Date or java.sql.Date with format dd/MM/yyyy HH:mm:ss
* Class represents a special cell editor which will open a calendar/date dialog in which a date and
* time can be selected. The class can return a java.util.Date or java.sql.Date with format
* dd/MM/yyyy HH:mm:ss
*
* @author Nikolaos Pringouris <nprigour@gmail.com>
* @since 2.0.0
Expand All @@ -46,20 +45,19 @@ public DateTimeCellEditor(Composite parent) {
super(parent);
}



@Override
protected Object openDialogBox(Control cellEditorWindow) {
DateTimePickerDialog dialog = new DateTimePickerDialog(cellEditorWindow.getShell(), "choose date:", true);
Date d= (Date) doGetValue();
DateTimePickerDialog dialog = new DateTimePickerDialog(cellEditorWindow.getShell(),
"choose date:", true);
Date d = (Date) doGetValue();
java.util.Calendar c = Calendar.getInstance();
if (d != null) {
c.setTime(d);
}
dialog.setDate(c);

if (dialog.open() != Dialog.CANCEL) {
if (dialog.shouldNullify()) {//call explicitly doSeValue passing null as argument
if (dialog.shouldNullify()) {// call explicitly doSeValue passing null as argument
doSetValue(null);
return null;
} else {
Expand All @@ -76,33 +74,33 @@ protected Object doGetValue() {
return null;
} else if (Date.class.isAssignableFrom(object.getClass())) {
return object;
} else if (object instanceof String) {
} else if (object instanceof String) {
try {
return format.parse((String)object);
return format.parse((String) object);
} catch (ParseException e) {
// probably a an empty String
//e.printStackTrace();
// e.printStackTrace();
}
}
return null;
}

@Override
protected void doSetValue(Object value) {
//if instance of Date apply the appropriate format
// if instance of Date apply the appropriate format
if (value instanceof Date) {
super.doSetValue(getDateFormatter().format(value));
} else {
super.doSetValue(value);
}
}

@Override
public boolean isValueValid() {
Object object = super.doGetValue();
if (object instanceof String) {
if (object instanceof String) {
try {
format.parse((String)object);
format.parse((String) object);
} catch (ParseException e) {
return false;
}
Expand All @@ -124,5 +122,4 @@ public void setDateFormatter(DateFormat format) {
this.format = format;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,29 @@
import org.eclipse.swt.widgets.Shell;

/**
* Class DatePickerDialog. A dialog where the user can select a dateValue using a month/dateValue view.
* The class provides an extra option for un-setting the dateValue value.
* Class DatePickerDialog. A dialog where the user can select a dateValue using a month/dateValue
* view. The class provides an extra option for un-setting the dateValue value.
*
* @author Nikolaos Pringouris <nprigour@gmail.com>
* @since 2.0.0
*/
public class DateTimePickerDialog extends Dialog {
//the calendar value to be set
// the calendar value to be set
private Calendar dateValue;

//attributes required to support nullify operation.
private Button unsetDateCheckbox;
// attributes required to support nullify operation.
private Button unsetDateCheckbox;

private boolean shouldNullify = false;

private boolean allowNullOption;

// a description title for the Dialog
private String description;

//the Date swt widget
// the Date swt widget
private DateTime swtCalendar;

private DateTime swtTime;

/**
Expand All @@ -65,14 +68,14 @@ public DateTimePickerDialog(Shell parent, String subject, boolean allowNullOPtio
super(parent);
description = subject;
setDate(null);
this.allowNullOption=allowNullOPtion;
this.allowNullOption = allowNullOPtion;
}

/**
* Set the dateValue (used as start dateValue in calendar)
*
* @param value dateValue to start with, if null, the current dateValue is used and displayed in the
* default locale
* @param value dateValue to start with, if null, the current dateValue is used and displayed in
* the default locale
*/
public void setDate(Calendar value) {
if (null == value) {
Expand All @@ -82,15 +85,20 @@ public void setDate(Calendar value) {
}
}

/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
*/
protected void configureShell(Shell newShell) {
//newShell.setText(Messages.getString("RCPDatePickerDialog.DatePickerTitle")); //$NON-NLS-1$
// newShell.setText(Messages.getString("RCPDatePickerDialog.DatePickerTitle"));
// //$NON-NLS-1$
super.configureShell(newShell);
}

/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea(Composite parent) {
Expand All @@ -109,8 +117,8 @@ protected Control createDialogArea(Composite parent) {

swtCalendar = new DateTime(client, SWT.DATE | SWT.BORDER);
swtTime = new DateTime(client, SWT.TIME | SWT.BORDER);
//TCHAR lpszFormat = new TCHAR (0, "dd/MM/yyyy", true);
//OS.SendMessage (swtCalendar.handle, OS.DTM_SETFORMAT, 0, lpszFormat);
// TCHAR lpszFormat = new TCHAR (0, "dd/MM/yyyy", true);
// OS.SendMessage (swtCalendar.handle, OS.DTM_SETFORMAT, 0, lpszFormat);
// double click does not work since the clicked area cannot be determined,
// it might have been at the month scroll button.
// swtCalendar.addMouseListener(new MouseAdapter()
Expand Down Expand Up @@ -143,7 +151,8 @@ protected void okPressed() {
if (unsetDateCheckbox != null && unsetDateCheckbox.getSelection()) {
shouldNullify = true;
} else {
dateValue.set(swtCalendar.getYear(), swtCalendar.getMonth(), swtCalendar.getDay(), swtTime.getHours(), swtTime.getMinutes());
dateValue.set(swtCalendar.getYear(), swtCalendar.getMonth(), swtCalendar.getDay(),
swtTime.getHours(), swtTime.getMinutes());
}
super.okPressed();
}
Expand All @@ -160,5 +169,4 @@ public boolean shouldNullify() {
return shouldNullify;
}


}
Loading

0 comments on commit cc16ca6

Please sign in to comment.