Example usage for javafx.collections ObservableList get

List of usage examples for javafx.collections ObservableList get

Introduction

In this page you can find the example usage for javafx.collections ObservableList get.

Prototype

E get(int index);

Source Link

Document

Returns the element at the specified position in this list.

Usage

From source file:com.ubershy.streamsis.project.CuteProject.java

/**
 * Validates list with Actors/SisScenes. <br>
 * Throws exceptions if something is wrong telling programmer about errors he made.
 *
 * @param list/*  w  w  w.  ja v a 2s.c  om*/
 *            the list with Actors or SisScenes
 */
private <T> void validateListOfActorsOrSisScenes(ObservableList<T> list) {
    if (list.isEmpty()) {
        return;
    }
    if (list.contains(null)) {
        throw new RuntimeException("One of the elements in list is null");
    }
    String elementType = null;
    Object firstElement = list.get(0);
    if (firstElement instanceof Actor) {
        elementType = "Actor";
    }
    if (firstElement instanceof SisScene) {
        elementType = "SisScene";
    }
    if (elementType == null) {
        throw new RuntimeException("This method only checks lists of Actors or SisScenes");
    }

    ArrayList<String> names = new ArrayList<String>();
    for (T element : list) {
        String name = ((CuteElement) element).getElementInfo().getName();
        if (name != null) {
            names.add(name);
        } else {
            throw new RuntimeException(elementType + " has null name");
        }
    }
    HashSet<String> uniqueNames = new HashSet<String>(names);
    if (names.size() != uniqueNames.size()) {
        throw new RuntimeException("Some of " + elementType + "s don't have unique names");
    }
}

From source file:condorclient.MainFXMLController.java

private void configureTable() {
    //selected.setCellValueFactory(new PropertyValueFactory<>("selected"))
    //s/*  w  w  w.j  a v a2  s  .  co  m*/

    table.getColumns().addAll(new TableColumn("??"), new TableColumn("ID"),
            new TableColumn("??"), new TableColumn(""),
            new TableColumn(""), new TableColumn(""), new TableColumn("?"),
            new TableColumn(""), new TableColumn("?"));

    //private 
    ObservableList<DisplayedClassAdStub> data = FXCollections.observableArrayList();

    ObservableList<TableColumn> observableList = table.getColumns();
    observableList.get(0).setCellValueFactory(new PropertyValueFactory(ColClusterNameMapKey));
    observableList.get(1).setCellValueFactory(new PropertyValueFactory(ColClusterIdMapKey));
    observableList.get(2).setCellValueFactory(new PropertyValueFactory(ColInfoFileNameMapKey));
    observableList.get(3).setCellValueFactory(new PropertyValueFactory(ColExpFileNameMapKey));
    observableList.get(4).setCellValueFactory(new PropertyValueFactory(ColTotalSampleNumMapKey));
    observableList.get(5).setCellValueFactory(new PropertyValueFactory(ColSubmittedTimeMapKey));
    observableList.get(6).setCellValueFactory(new PropertyValueFactory(ColRunTimeMapKey));
    observableList.get(7).setCellValueFactory(new PropertyValueFactory(ColProcessStatusMapKey));
    observableList.get(7).setCellFactory(ProgressBarTableCell.forTableColumn());
    observableList.get(8).setCellValueFactory(new PropertyValueFactory(ColJobStatusMapKey));

    table.setItems(tableContent);
    tablePane.getChildren().add(table);
    // table.setSelectionModel(null);
    //sampleTab
    sampleTab.getColumns().addAll(new TableColumn("?"), new TableColumn(""),
            new TableColumn("??"), new TableColumn("?"), new TableColumn(""),
            new TableColumn("?"), new TableColumn(""), new TableColumn("?"));
    ((TableColumn) sampleTab.getColumns().get(6)).setVisible(false);
    ((TableColumn) sampleTab.getColumns().get(2)).setPrefWidth(150);
    ((TableColumn) sampleTab.getColumns().get(5)).setPrefWidth(50);
    ((TableColumn) sampleTab.getColumns().get(7)).setPrefWidth(150);
    //private 
    ObservableList<DisplayedClassAdStub> sampleData = FXCollections.observableArrayList();

    ObservableList<TableColumn> sampleList = sampleTab.getColumns();
    sampleList.get(0).setCellValueFactory(new PropertyValueFactory(ColSampleIdMapKey));
    sampleList.get(1).setCellValueFactory(new PropertyValueFactory(ColEachRunMapKey));
    sampleList.get(2).setCellValueFactory(new PropertyValueFactory(ColSampleSubmittedTimeMapKey));
    sampleList.get(3).setCellValueFactory(new PropertyValueFactory(ColSampleRunTimeMapKey));
    sampleList.get(4).setCellValueFactory(new PropertyValueFactory(ColSampleProcessStatusMapKey));
    sampleList.get(4).setCellFactory(ProgressBarTableCell.forTableColumn());
    sampleList.get(5).setCellValueFactory(new PropertyValueFactory(ColSampleJobStatusMapKey));
    sampleList.get(6).setCellValueFactory(new PropertyValueFactory(ColCpuIdMapKey));
    sampleList.get(7).setCellValueFactory(new PropertyValueFactory(ColSlotIdMapKey));

    sampleTab.setItems(sampleContent);
    sampleBox.getChildren().add(sampleTab);

    //end sampleTab
    // ColConnectInfoMapKey  ColIpMapKey ColMachineIdMapKey ColMemMapKey ColDiskMapKey ColSlotNumMapKey
    //ColJobNameMapKey  ColJobCpuMapKey ColJobMemMapKey
    colConnectInfo.setCellValueFactory(new PropertyValueFactory<>(ColConnectInfoMapKey));
    colIp.setCellValueFactory(new PropertyValueFactory<>(ColIpMapKey));
    colMachineId.setCellValueFactory(new PropertyValueFactory<>(ColMachineIdMapKey));
    colMem.setCellValueFactory(new PropertyValueFactory<>(ColMemMapKey));
    colSlotNum.setCellValueFactory(new PropertyValueFactory<>(ColSlotNumMapKey));
    colDisk.setCellValueFactory(new PropertyValueFactory<>(ColDiskMapKey));
    colCpu.setCellValueFactory(new PropertyValueFactory<>(ColCpuMapKey));
    resourcesTab.setItems(resourcesContent);
    //resourcesTab.setSelectionModel(null);

    colJobName.setCellValueFactory(new PropertyValueFactory<>(ColJobNameMapKey));
    colJobCpu.setCellValueFactory(new PropertyValueFactory<>(ColJobCpuMapKey));
    colJobMem.setCellValueFactory(new PropertyValueFactory<>(ColJobMemMapKey));
    job_resourcesTab.setItems(jobContent);
    job_resourcesTab.setSelectionModel(null);

}

From source file:com.saiton.ccs.validations.FormatAndValidate.java

public boolean isListViewItemDuplicated(ListView listView, String value) {

    boolean valid = false;
    ObservableList<String> list = listView.getItems();

    if (list.size() != 0 && !value.isEmpty()) {
        for (int i = 0; i < list.size(); i++) {

            if (!list.get(i).equals(value)) {
                valid = true;//from   w w  w . j av a 2  s . com

            }
        }

    } else if (list.size() == 0) {
        valid = true;
    }
    return valid;
}

From source file:com.github.naoghuman.testdata.abclist.service.ExerciseTermService.java

@Override
protected Task<Void> createTask() {
    return new Task<Void>() {
        {/* ww  w.  ja  v a 2 s  .com*/
            updateProgress(0, saveMaxEntities);
        }

        @Override
        protected Void call() throws Exception {
            LoggerFacade.getDefault().deactivate(Boolean.TRUE);

            final StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            final ObservableList<Topic> topics = SqlProvider.getDefault().findAllTopics();
            final ObservableList<Term> terms = SqlProvider.getDefault().findAllTerms();
            final int sizeTerms = terms.size();
            final AtomicInteger index = new AtomicInteger(0);

            final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName);
            final AtomicLong id = new AtomicLong(
                    -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName));
            topics.stream().forEach(topic -> {
                final ObservableList<Exercise> exercises = SqlProvider.getDefault()
                        .findAllExercisesWithTopicId(topic.getId());
                exercises.stream().filter(exercise -> exercise.isReady()).forEach(exercise -> {
                    final int maxExerciseTerms = TestdataGenerator.RANDOM.nextInt(70) + 10;
                    for (int i = 0; i < maxExerciseTerms; i++) {
                        final Term term = terms.get(TestdataGenerator.RANDOM.nextInt(sizeTerms));
                        final ExerciseTerm exerciseTerm = ModelProvider.getDefault().getExerciseTerm();
                        exerciseTerm.setExerciseId(exercise.getId());
                        exerciseTerm.setId(id.getAndIncrement());
                        exerciseTerm.setTermId(term.getId());

                        crudService.create(exerciseTerm);
                    }
                });

                updateProgress(index.getAndIncrement(), saveMaxEntities);
            });

            LoggerFacade.getDefault().deactivate(Boolean.FALSE);
            stopWatch.split();
            LoggerFacade.getDefault().debug(this.getClass(),
                    "  + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " ExerciseTerms."); // NOI18N
            stopWatch.stop();

            return null;
        }
    };
}

From source file:com.saiton.ccs.validations.FormatAndValidate.java

public boolean isValidVehicleNo(ListView listView, String vehicleNo) {
    boolean valid = true;

    String vehicleNoTrimed = vehicleNo.trim();
    ObservableList<String> list = listView.getItems();

    if (vehicleNoTrimed.length() < 14 && vehicleNoTrimed.length() > 4) {

        if (list.size() != 0 && !vehicleNo.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {

                if (list.get(i).equals(vehicleNo)) {
                    valid = false;/*from   ww w .jav  a2  s .c o  m*/

                }
                //                    else {
                //
                //                        valid = false;
                //
                //                    }
            }
        } else if (list.size() == 0) {
            valid = true;
        }

    } else {

        valid = false;
    }

    return valid;

}

From source file:com.saiton.ccs.validations.FormatAndValidate.java

public boolean isValidUniqueEmail(ListView listView, String email) {

    boolean valid = true;
    ObservableList<String> list = listView.getItems();
    boolean isEmail = org.apache.commons.validator.routines.EmailValidator.getInstance().isValid(email);

    if (isEmail == true) {
        if (list.size() != 0 && !email.isEmpty()) {
            for (int i = 0; i < list.size(); i++) {

                if (list.get(i).equals(email)) {
                    valid = false;// www  . jav a  2  s.  com
                }
                //                    else {
                //                        valid = false;
                //                    }

            }
        } else if (list.size() == 0) {
            valid = true;
        }
    }

    return valid;

}

From source file:org.jevis.jeconfig.plugin.classes.ClassTree.java

public void fireEventExport(ObservableList<TreeItem<JEVisClass>> items) {

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Save JEVisClasses to File");
    fileChooser.getExtensionFilters().addAll(new ExtensionFilter("JEVis Files", "*.jev"),
            new ExtensionFilter("All Files", "*.*"));

    DateTime now = DateTime.now();//from w w w  .ja v a2 s  . c om
    DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
    if (items.size() > 1) {
        fileChooser.setInitialFileName("JEViClassExport_" + fmt.print(now) + ".jev");
    } else {
        try {
            fileChooser.setInitialFileName(items.get(0).getValue().getName() + "_" + fmt.print(now) + ".jev");
        } catch (JEVisException ex) {
            Logger.getLogger(ClassTree.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    File selectedFile = fileChooser.showSaveDialog(JEConfig.getStage());
    if (selectedFile != null) {
        List<JEVisClass> classes = new ArrayList<>();
        for (TreeItem<JEVisClass> item : items) {
            classes.add(item.getValue());
        }

        String extension = FilenameUtils.getExtension(selectedFile.getName());
        if (extension.isEmpty()) {
            selectedFile = new File(selectedFile.getAbsoluteFile() + ".jsv");
        }

        ClassExporter ce = new ClassExporter(selectedFile, classes);
        //            mainStage.display(selectedFile);
    }
}

From source file:csg.files.CSGFiles.java

public void saveScheduleData(AppDataComponent schData, String filePath) throws IOException {
    ScheduleData schDataManager = (ScheduleData) schData;
    JsonArrayBuilder schArrayBuilder = Json.createArrayBuilder();
    ObservableList<ScheduleItem> schedule = schDataManager.getSchedule();

    ArrayList<ScheduleItem> holidays = new ArrayList();
    ArrayList<ScheduleItem> lectures = new ArrayList();
    ArrayList<ScheduleItem> references = new ArrayList();
    ArrayList<ScheduleItem> recitations = new ArrayList();
    ArrayList<ScheduleItem> hws = new ArrayList();

    for (int i = 0; i < schedule.size(); i++) {
        if (schedule.get(i).getType().equals("holiday")) {
            holidays.add(schedule.get(i));
        } else if (schedule.get(i).getType().equals("lecture")) {
            lectures.add(schedule.get(i));
        } else if (schedule.get(i).getType().equals("reference")) {
            references.add(schedule.get(i));
        } else if (schedule.get(i).getType().equals("recitation")) {
            recitations.add(schedule.get(i));
        } else if (schedule.get(i).getType().equals("hw")) {
            hws.add(schedule.get(i));/*w w w .  ja  va2 s  .co m*/
        }
    }

    JsonArrayBuilder holidayArrayBuilder = Json.createArrayBuilder();
    for (ScheduleItem scheduleItem : holidays) {
        JsonObject holidayJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon())
                .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle())
                .add(JSON_LINK, scheduleItem.getLink()).build();
        holidayArrayBuilder.add(holidayJson);
    }
    JsonArray holidayArray = holidayArrayBuilder.build();

    JsonArrayBuilder lectureArrayBuilder = Json.createArrayBuilder();
    for (ScheduleItem scheduleItem : lectures) {
        JsonObject lecJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon())
                .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle())
                .add(JSON_TOPIC, scheduleItem.getTopic()).add(JSON_LINK, scheduleItem.getLink()).build();
        lectureArrayBuilder.add(lecJson);
    }
    JsonArray lectureArray = lectureArrayBuilder.build();

    JsonArrayBuilder referencesArrayBuilder = Json.createArrayBuilder();
    for (ScheduleItem scheduleItem : references) {
        JsonObject lecJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon())
                .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle())
                .add(JSON_TOPIC, scheduleItem.getTopic()).add(JSON_LINK, scheduleItem.getLink()).build();
        referencesArrayBuilder.add(lecJson);
    }
    JsonArray referenceArray = referencesArrayBuilder.build();

    JsonArrayBuilder recitationArrayBuilder = Json.createArrayBuilder();
    for (ScheduleItem scheduleItem : recitations) {
        JsonObject lecJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon())
                .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle())
                .add(JSON_TOPIC, scheduleItem.getTopic()).build();
        recitationArrayBuilder.add(lecJson);
    }
    JsonArray recitaitonArray = recitationArrayBuilder.build();

    JsonArrayBuilder hwArrayBuilder = Json.createArrayBuilder();
    for (ScheduleItem scheduleItem : hws) {
        JsonObject lecJson = Json.createObjectBuilder().add(JSON_MONTH, scheduleItem.getDateMon())
                .add(JSON_DAY, scheduleItem.getDateDay()).add(JSON_TITLE, scheduleItem.getTitle())
                .add(JSON_TOPIC, scheduleItem.getTopic()).add(JSON_LINK, scheduleItem.getLink())
                .add(JSON_TIME, scheduleItem.getTime()).add(JSON_CRITERIA, scheduleItem.getCriteria()).build();
        hwArrayBuilder.add(lecJson);
    }
    JsonArray hwArray = hwArrayBuilder.build();

    JsonObject dataManagerJSO = Json.createObjectBuilder().add(JSON_MONDAYMON, workspace.getMonMonthDate())
            .add(JSON_MONDAYDAY, workspace.getMonDayDate()).add(JSON_FRIDAYMONTH, workspace.getFriMonthDate())
            .add(JSON_FRIDAYDAY, workspace.getFriDayDate()).add(JSON_HOLIDAYS, holidayArray)
            .add(JSON_LECTURES, lectureArray).add(JSON_REF, referenceArray)
            .add(JSON_RECITATION, recitaitonArray).add(JSON_HW, hwArray).build();

    // AND NOW OUTPUT IT TO A JSON FILE WITH PRETTY PRINTING
    Map<String, Object> properties = new HashMap<>(1);
    properties.put(JsonGenerator.PRETTY_PRINTING, true);
    JsonWriterFactory writerFactory = Json.createWriterFactory(properties);
    StringWriter sw = new StringWriter();
    JsonWriter jsonWriter = writerFactory.createWriter(sw);
    jsonWriter.writeObject(dataManagerJSO);
    jsonWriter.close();

    // INIT THE WRITER
    OutputStream os = new FileOutputStream(filePath);
    JsonWriter jsonFileWriter = Json.createWriter(os);
    jsonFileWriter.writeObject(dataManagerJSO);
    String prettyPrinted = sw.toString();
    PrintWriter pw = new PrintWriter(filePath);
    pw.write(prettyPrinted);
    pw.close();
}

From source file:com.github.drbookings.ui.controller.MainController.java

private LocalDate getSelectedDate() {
    ObservableList<DateBean> selectedDate = tableView.getSelectionModel().getSelectedItems();
    if (logger.isDebugEnabled()) {
        logger.debug("Selected date: " + selectedDate);
    }//from  w  w w  .ja va 2 s  .  co m
    LocalDate selectedDate2;
    if (selectedDate == null || selectedDate.isEmpty()) {
        selectedDate2 = LocalDate.now();
    } else {
        selectedDate2 = selectedDate.get(0).getDate();
    }
    return selectedDate2;
}

From source file:com.github.naoghuman.testdata.abclist.service.LinkMappingService.java

@Override
protected Task<Void> createTask() {
    return new Task<Void>() {
        {//from  w  ww .j av a  2  s.  com
            updateProgress(0, saveMaxEntities);
        }

        @Override
        protected Void call() throws Exception {
            LoggerFacade.getDefault().deactivate(Boolean.TRUE);

            final StopWatch stopWatch = new StopWatch();
            stopWatch.start();

            /*
             1) over all links
             2) if random > 0.005d then do
             3) otherwise create a link without parent
             4) get 1-10 terms, create LinkMapping foreach of them
             - means a link is mapped to 1-10 terms
             5) get 0-10 topics, create LinkMapping foreach of them
             - means a link is mapped to 0-10 topics
            */

            final ObservableList<Link> links = SqlProvider.getDefault().findAllLinks();
            final ObservableList<Term> terms = SqlProvider.getDefault().findAllTerms();
            final int sizeTerms = terms.size();
            final ObservableList<Topic> topics = SqlProvider.getDefault().findAllTopics();
            final int sizeTopics = topics.size();
            final AtomicInteger index = new AtomicInteger(0);

            final CrudService crudService = DatabaseFacade.getDefault().getCrudService(entityName);
            final AtomicLong id = new AtomicLong(
                    -1_000_000_000L + DatabaseFacade.getDefault().getCrudService().count(entityName));
            links.stream() // 1
                    .forEach(link -> {
                        // 2) Should the [Link] have a parent
                        final double random = TestdataGenerator.RANDOM.nextDouble();
                        if (random > 0.005d) {
                            // 4) Create [Link]s with parent [Term]
                            final int maxTerms = TestdataGenerator.RANDOM.nextInt(10) + 1;
                            for (int i = 0; i < maxTerms; i++) {
                                final LinkMapping lm = ModelProvider.getDefault().getLinkMapping();
                                lm.setId(id.getAndIncrement());

                                final Term term = terms.get(TestdataGenerator.RANDOM.nextInt(sizeTerms));
                                lm.setParentId(term.getId());
                                lm.setParentType(LinkMappingType.TERM);

                                lm.setChildId(link.getId());
                                lm.setChildType(LinkMappingType.LINK);

                                crudService.create(lm);
                            }

                            // 5) Create [Link]s with parent [Topic]
                            final int maxTopics = TestdataGenerator.RANDOM.nextInt(11);
                            for (int i = 0; i < maxTopics; i++) {
                                final LinkMapping lm = ModelProvider.getDefault().getLinkMapping();
                                lm.setId(id.getAndIncrement());

                                final Topic topic = topics.get(TestdataGenerator.RANDOM.nextInt(sizeTopics));
                                lm.setParentId(topic.getId());
                                lm.setParentType(LinkMappingType.TOPIC);

                                lm.setChildId(link.getId());
                                lm.setChildType(LinkMappingType.LINK);

                                crudService.create(lm);
                            }
                        } else {
                            // 3) Some [Link]s havn't a parent
                            final LinkMapping lm = ModelProvider.getDefault().getLinkMapping();
                            lm.setId(id.getAndIncrement());
                            lm.setParentId(IDefaultConfiguration.DEFAULT_ID);
                            lm.setParentType(LinkMappingType.NOT_DEFINED);
                            lm.setChildId(link.getId());
                            lm.setChildType(LinkMappingType.LINK);

                            crudService.create(lm);
                        }

                        updateProgress(index.getAndIncrement(), saveMaxEntities);
                    });

            LoggerFacade.getDefault().deactivate(Boolean.FALSE);
            stopWatch.split();
            LoggerFacade.getDefault().debug(this.getClass(),
                    "  + " + stopWatch.toSplitString() + " for " + saveMaxEntities + " LinkMappings."); // NOI18N
            stopWatch.stop();

            return null;
        }
    };
}