/** Contructor */ Application() { // inicalizes the lists users = new PersonList("Pessoas.dat", Person.PersonTypes.USER); techs = new PersonList("Pessoas.dat", Person.PersonTypes.WORKER); posts = new StationList("Postos_trab.dat"); tickets = new TicketList("Pedidos.txt", "Intervencoes.txt", users, techs, posts); // loads files posts.loadFile(); users.loadFile(); techs.loadFile(); tickets.loadFile(); }
public List<Person> getAll() throws DatabaseException { List<Person> list = null; try { context = JAXBContext.newInstance(PersonList.class); Unmarshaller um = context.createUnmarshaller(); PersonList pl = (PersonList) um.unmarshal(new FileReader(DATASOURCE)); list = pl.getPersonList(); } catch (JAXBException e) { e.printStackTrace(); throw new DatabaseException("Failed to connect to database"); } catch (FileNotFoundException e) { e.printStackTrace(); throw new DatabaseException("Failed to connect to database"); } return list; }
/** displayList */ public void displayList(String code) { // 入力された職種をもつ従業員のレコードだけを // selectedListに取り出す selectedList = plist.searchByTypes(work); listsize = selectedList.size(); if (listsize <= 0) System.out.println("従業員が存在しません。"); else { if (code.equals(" ") && next_start_id == 0) { System.out.println("最初のページを表示"); int rows = listsize >= 3 ? 3 : listsize; for (int i = 0; i < rows; i++) { System.out.println(selectedList.getRecord(i).toString()); } start_id = next_start_id; next_start_id = rows; } else if (code.equals("N")) { if (listsize > next_start_id) { System.out.println("次のページを表示"); int rows = listsize - next_start_id >= 3 ? 3 : listsize - next_start_id; for (int i = next_start_id; i < next_start_id + rows; i++) { System.out.println(selectedList.getRecord(i).toString()); } start_id = next_start_id; next_start_id += rows; } else { System.out.println("最後まで表示して頭に戻りました"); int rows = listsize >= 3 ? 3 : listsize; for (int i = 0; i < rows; i++) { System.out.println(selectedList.getRecord(i).toString()); } start_id = 0; next_start_id = rows; } } else if (code.equals("P")) { System.out.println("next_start_id:" + next_start_id); System.out.println("start_id: " + start_id); if (start_id >= 3) { System.out.println("前のページを表示"); if (next_start_id >= 6) { next_start_id = start_id - 3; } else { next_start_id = 0; } for (int i = next_start_id; i < next_start_id + 3; i++) { System.out.println(selectedList.getRecord(i).toString()); } start_id = next_start_id; next_start_id += 3; } else { System.out.println("末尾の3件を表示"); next_start_id = listsize >= 3 ? listsize - 3 : 0; for (int i = next_start_id; i < listsize; i++) { System.out.println(selectedList.getRecord(i).toString()); } start_id = next_start_id; next_start_id = listsize; } } } }
/** exit's the application */ public void exit() { // saves posts posts.saveFile(); // saves users and techs in one file PersonList pl = new PersonList("Pessoas.dat", Person.PersonTypes.ALL); for (int i = 0; i < users.size(); i++) pl.add(users.get(i)); for (int i = 0; i < techs.size(); i++) pl.add(techs.get(i)); pl.saveFile(); tickets.saveFile(); System.exit(0); }
/** * getNextStatus * * @param String s * @return ConsoleStatus */ public ConsoleStatus getNextStatus(String s) { if (s.equals("N") || s.equals("P")) { displayList(s); return this; } else { start_id = 0; next_start_id = 0; // 数値が入力された場合,その数値と同じIDをもつ // レコードがselectedListにあるかどうか判定し, // あればそれを次の状態DisplayPersonStatusに try { int i = Integer.parseInt(s); Person p = selectedList.get(i); if (p == null) return this; else { next.setPersonRecord(p); return next; } } catch (NumberFormatException e) { return super.getNextStatus(s); } } }
private Component initSearchButton(TextField searchField) { Button button = new Button(new ThemeResource("images/find.png")); button.setStyleName("form-button"); button.addClickListener(event -> personList.setPersons(search(searchField.getValue()))); return button; }