Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Copyright 2012-2015 the original author or authors.
 
 package org.assertj.swing.jide.grids.driver;
 
 import static org.junit.Assert.assertTrue;
 
 import java.util.Date;
 
 
 
 import  com.jidesoft.combobox.DateChooserPanel;
 import  com.jidesoft.combobox.DateComboBox;

A basic rudimentary Driver for the com.jidesoft.combobox.DateComboBox class.

Author(s):
Peter Murray
 
 public class DateComboBoxDriver extends JComponentDriver {
 
   public DateComboBoxDriver(Robot robot) {
 	super(robot);
   }
 
   public Date getSelectedDate(final DateComboBox combo) {
 	GuiQuery<Datequery = new GuiQuery<Date>() {
 	  @Override
 	  protected Date executeInEDT() throws Throwable {
 		return combo.getDate();
 	  }
 	};
 	return GuiActionRunner.execute(query);
   }
 
   public Calendar getSelectedCalendar(final DateComboBox combo) {
 	GuiQuery<Calendarquery = new GuiQuery<Calendar>() {
 	  @Override
 	  protected Calendar executeInEDT() throws Throwable {
 		return combo.getCalendar();
 	  }
 	};
 	return GuiActionRunner.execute(query);
   }
 
   public void selectToday(final DateComboBox combo) {
 	showPopup(combo);
 	String buttonName = combo.isTimeDisplayed() ? "Date.now" : "Date.today";
 
 	ComponentFinder finder = BasicComponentFinder.finderWithCurrentAwtHierarchy();
 	final JButton btn = finder.findByName(buttonNameJButton.class);
 	if (btn == null) {
 	  throw new IllegalStateException("Could not find the today/now button to click.");
 	}
 	.click(btn);
   }
 
   public void selectDate(DateComboBox combofinal Date d) {
 	Date current = combo.getDate();
 	if (current == null && d == null || current != null && current.equals(d)) {
 	  return;
 	}
 	showPopup(combo);
 	DateChooserPanel panel = (DateChooserPanel) combo.getPopupPanel();
 	selectDateOnPanel(paneld);
   }
 
   public void selectCalendar(DateComboBox combofinal Calendar cal) {
 	selectDate(combocal.getTime());
   }
 
   private static void showPopup(final DateComboBox combo) {
 	GuiTask task = new GuiTask() {
 	  @Override
	  protected void executeInEDT() throws Throwable {
		if (!combo.isPopupVisible()) {
		  combo.showPopup();
		}
		assertTrue("The popup should be visible"combo.isPopupVisible());
	  }
	};
	GuiActionRunner.execute(task);
  }
  private static void selectDateOnPanel(final DateChooserPanel panelfinal Date d) {
	GuiTask task = new GuiTask() {
	  protected void executeInEDT() throws Throwable {
		panel.setSelectedDate(d);
	  }
	};
	GuiActionRunner.execute(task);
  }
New to GrepCode? Check out our FAQ X