package ksiazka.kucharska;
|
|
|
|
import java.util.List;
|
|
|
|
import javax.swing.DefaultListModel;
|
|
import javax.swing.ImageIcon;
|
|
|
|
import db.Cookbook;
|
|
import db.Recipe;
|
|
import ksiazka.kucharska.FrmMain;
|
|
|
|
public class RetrieveData extends FrmMain{
|
|
/**
|
|
*
|
|
*/
|
|
private static final long serialVersionUID = 1L;
|
|
public static void insertSampleData(){
|
|
Cookbook myCb = new Cookbook();
|
|
myCb.insertRecipe("Kanapka",
|
|
"Chleb, margaryna, szynka",
|
|
"Posmarować kanapke margaryną i położyć na niej plaster szynki",
|
|
"kanapka, szynka, chleb", imgDefaultRecipe);
|
|
myCb.insertRecipe("Kanapka z sererm",
|
|
"Chleb, margaryna, ser",
|
|
"Posmarować kanapke margaryną i położyć na niej plaster sera",
|
|
"kanapka, ser, chleb", imgDefaultRecipe);
|
|
myCb.closeConnection();
|
|
}
|
|
public static void fillList(){
|
|
Cookbook myCb = new Cookbook();
|
|
List<String> names = myCb.selectNames();
|
|
|
|
DefaultListModel recipesList;
|
|
recipesList = getRecipesList();
|
|
|
|
for (String r : names)
|
|
{
|
|
recipesList.addElement(r);
|
|
}
|
|
myCb.closeConnection();
|
|
}
|
|
public static void fillComponents(String name){
|
|
Cookbook myCb = new Cookbook();
|
|
Recipe myRecipe = myCb.selectRecipe(name);
|
|
lblRecipeTitle.setText(name);
|
|
txtIngredients.setText(myRecipe.getIngredients());
|
|
txtDescription.setText(myRecipe.getDescription());
|
|
txtTags.setText(myRecipe.getTags());
|
|
imgRecipe.setIcon(myRecipe.getImage());
|
|
myCb.closeConnection();
|
|
}
|
|
public static void addNewRecipe(){
|
|
Cookbook myCb = new Cookbook();
|
|
|
|
RecipeManager rm = new RecipeManager();
|
|
rm.setRecipeBuilder(new NewRecipeBuilder());
|
|
rm.constructRecipe();
|
|
|
|
Recipe 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();
|
|
}
|
|
}
|