Cook book written in Java
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

82 lines
2.0 KiB

package ksiazka.kucharska;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import db.AllRecipes;
import db.Cookbook;
import db.Recipe;
import db.SearchRecipe;
import db.SearchRecipeNameTag;
public class RetrieveData extends FrmMain{
/**
*
*/
private static final long serialVersionUID = 1L;
public static void insertSampleData(){
Cookbook myCb = new Cookbook();
RecipeManager rm = new RecipeManager();
rm.setRecipeBuilder(new ExampleRecipeBuilder());
rm.constructRecipe();
Recipe rc = rm.getRecipe();
myCb.insertRecipe(rc);
myCb.closeConnection();
}
public static void fillList(){
Cookbook myCb = new Cookbook();
SearchRecipe sr;
if (txtSearch.getText() != "") {
sr = new SearchRecipeNameTag();
}
else
{
sr = new AllRecipes();
}
List<String> names = sr.obtainRecipeNames();
DefaultListModel recipesList;
recipesList = getRecipesList();
recipesList.clear();
for (String r : names)
{
recipesList.addElement(r);
}
myCb.closeConnection();
}
public static void fillComponents(String name){
Cookbook myCb = new Cookbook();
CB_Model myRecipe = myCb.selectRecipe(name);
lblRecipeTitle.setText(name);
txtIngredients.setText(myRecipe.getIngredients());
txtDescription.setText(myRecipe.getDescription());
txtTags.setText(myRecipe.getTags());
imgRecipe.setIcon(myRecipe.getImage());
txtDescription.setCaretPosition(0);
txtIngredients.setCaretPosition(0);
myCb.closeConnection();
}
public static void addNewRecipe(){
Cookbook myCb = new Cookbook();
RecipeManager rm = new RecipeManager();
rm.setRecipeBuilder(new NewRecipeBuilder());
rm.constructRecipe();
CB_Model obj = rm.getRecipe();
myCb.insertRecipe(obj);
//myCb.insertRecipe(txtEdTitle.getText(), txtIngredients.getText(), txtDescription.getText(), txtTags.getText(), (ImageIcon)imgRecipe.getIcon());
myCb.closeConnection();
}
public static void removeRecipe(String name){
Cookbook myCb = new Cookbook();
myCb.deleteRecipe(name);
myCb.closeConnection();
}
}