Java Code Examples for javafx.collections.ObservableList#clear()

The following examples show how to use javafx.collections.ObservableList#clear() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReasonEditorController.java    From OEE-Designer with MIT License 6 votes vote down vote up
private void populateTopReasonNodes() throws Exception {
	tvReasons.getSelectionModel().clearSelection();

	// fetch the reasons
	List<Reason> reasons = PersistenceService.instance().fetchTopReasons();
	Collections.sort(reasons);

	// add them to the root reason
	ObservableList<TreeItem<ReasonNode>> children = getRootReasonItem().getChildren();
	children.clear();

	for (Reason reason : reasons) {
		TreeItem<ReasonNode> reasonItem = new TreeItem<>(new ReasonNode(reason));
		children.add(reasonItem);
		reasonItem.setGraphic(ImageManager.instance().getImageView(Images.REASON));
	}

	// refresh tree view
	getRootReasonItem().setExpanded(true);
	tvReasons.refresh();
}
 
Example 2
Source File: MainController.java    From logbook-kai with MIT License 6 votes vote down vote up
/**
 * 泊地修理タイマー
 */
private void akashiTimer() {
    ObservableList<Node> nodes = this.akashiTimer.getChildren();

    if (AppCondition.get().getAkashiTimer() == 0) {
        if (!nodes.isEmpty()) {
            nodes.clear();
        }
    } else {
        if (nodes.isEmpty()) {
            nodes.add(new AkashiTimerPane());
        } else {
            ((AkashiTimerPane) nodes.get(0)).update();
        }
    }
}
 
Example 3
Source File: FilterList.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Fill a list of filters.
 *
 * @param sceneNode the scene node
 */
@FxThread
public void fill(@NotNull final SceneNode sceneNode) {

    final MultipleSelectionModel<EditableSceneFilter> selectionModel = listView.getSelectionModel();
    final EditableSceneFilter selected = selectionModel.getSelectedItem();

    final ObservableList<EditableSceneFilter> items = listView.getItems();
    items.clear();

    final List<SceneFilter> filters = sceneNode.getFilters();
    filters.stream().filter(EditableSceneFilter.class::isInstance)
            .map(EditableSceneFilter.class::cast)
            .forEach(items::add);

    if (selected != null && filters.contains(selected)) {
        selectionModel.select(selected);
    }
}
 
Example 4
Source File: PhysicalModelController.java    From OEE-Designer with MIT License 6 votes vote down vote up
void populateTopEntityNodes() throws Exception {
	// fetch the entities
	List<PlantEntity> entities = PersistenceService.instance().fetchTopPlantEntities();

	Collections.sort(entities);

	// add them to the root entity
	ObservableList<TreeItem<EntityNode>> children = getRootEntityItem().getChildren();
	children.clear();

	for (PlantEntity entity : entities) {
		TreeItem<EntityNode> entityItem = new TreeItem<>(new EntityNode(entity));
		children.add(entityItem);
		setEntityGraphic(entityItem);
	}

	// refresh tree view
	getRootEntityItem().setExpanded(true);
	tvEntities.getSelectionModel().clearSelection();
	tvEntities.refresh();

	if (entities.size() == 1 && (entities.get(0) instanceof Equipment)) {
		tvEntities.getSelectionModel().select(0);
	}
}
 
Example 5
Source File: CollectionBindings.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Maps an {@link ObservableValue<I>} object to an {@link ObservableList} by applying the given converter function
 * and adding the result to the {@link ObservableList}.
 * In case the input value is empty, i.e. contains <code>null</code>, the returned {@link ObservableList} is also
 * empty
 *
 * @param property The input value
 * @param converter The converter function
 * @param <I> The type of the input value
 * @param <O> The type of the output value
 * @return A {@link ObservableList} containing the converted list
 */
public static <I, O> ObservableList<O> mapToList(ObservableValue<I> property,
        Function<I, ? extends Collection<O>> converter) {
    final ObservableList<O> result = FXCollections.observableArrayList();

    final InvalidationListener listener = (Observable invalidation) -> {
        final I input = property.getValue();

        if (input != null) {
            result.setAll(converter.apply(input));
        } else {
            result.clear();
        }
    };

    // add the listener to the property
    property.addListener(listener);

    // ensure that the result list is initialised correctly
    listener.invalidated(property);

    return result;
}
 
Example 6
Source File: MaterialFileEditor.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Reload the material.
 */
@FxThread
private void reload(@NotNull final Material material) {
    setCurrentMaterial(material);
    setIgnoreListeners(true);
    try {

        final MaterialEditor3DPart editor3DState = getEditor3DPart();
        editor3DState.updateMaterial(material);

        getSettingsTree().fill(new RootMaterialSettings(material));

        final ComboBox<String> materialDefinitionBox = getMaterialDefinitionBox();
        final ObservableList<String> items = materialDefinitionBox.getItems();
        items.clear();
        items.addAll(RESOURCE_MANAGER.getAvailableResources(FileExtensions.JME_MATERIAL_DEFINITION));

        final MaterialDef materialDef = material.getMaterialDef();
        materialDefinitionBox.getSelectionModel().select(materialDef.getAssetName());

    } finally {
        setIgnoreListeners(false);
    }
}
 
Example 7
Source File: CreateTerrainDialog.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Update a list of available path sizes.
 */
@FxThread
private void updatePathSizeValues() {

    final ComboBox<Integer> pathSizeComboBox = getPatchSizeComboBox();
    final SingleSelectionModel<Integer> selectionModel = pathSizeComboBox.getSelectionModel();
    final Integer current = selectionModel.getSelectedItem();

    final ObservableList<Integer> items = pathSizeComboBox.getItems();
    items.clear();

    final ComboBox<Integer> totalSizeComboBox = getTotalSizeComboBox();
    final Integer naxValue = totalSizeComboBox.getSelectionModel().getSelectedItem();

    for (final Integer value : PATCH_SIZE_VARIANTS) {
        if (value >= naxValue) break;
        items.add(value);
    }

    if (items.contains(current)) {
        selectionModel.select(current);
    } else {
        selectionModel.select(items.get(items.size() - 1));
    }
}
 
Example 8
Source File: GenerateLodLevelsDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Clear added levels.
 */
@FxThread
private void clearLevels() {
    final ListView<Number> levelsList = getLevelsList();
    final ObservableList<Number> items = levelsList.getItems();
    items.clear();
}
 
Example 9
Source File: TextureLayerSettings.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Refresh the layers list.
 */
@FxThread
public void refresh() {

    final ListView<TextureLayer> listView = getListView();
    final MultipleSelectionModel<TextureLayer> selectionModel = listView.getSelectionModel();
    final TextureLayer selectedItem = selectionModel.getSelectedItem();

    final ObservableList<TextureLayer> items = listView.getItems();
    items.clear();

    final int maxLevels = getMaxLevels() - 1;

    for (int i = 0; i < maxLevels; i++) {

        final float scale = getTextureScale(i);
        if (scale == -1F) {
            continue;
        }

        items.add(new TextureLayer(this, i));
    }

    if (items.contains(selectedItem)) {
        selectionModel.select(selectedItem);
    } else if (!items.isEmpty()) {
        selectionModel.select(items.get(0));
    }

    final ExecutorManager executorManager = ExecutorManager.getInstance();
    executorManager.addFxTask(this::refreshHeight);
    executorManager.addFxTask(this::refreshAddButton);
}
 
Example 10
Source File: MainAction.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void serviceFilterKeyUpAction() {
    ObservableList items = mc.serviceList.getItems();
    if (itemsCache.isEmpty() && items != null) {
        items.forEach((item) -> {
            itemsCache.add((DubboServiceModel) item);
        });
    }
    String filter = mc.serviceFilter.getText();
    if ((filter == null || filter.trim().isEmpty()) && items != null) {
        items.clear();
        items.addAll(itemsCache.toArray());
    } else {
        items.clear();
        FilterType ft = (FilterType) mc.filterType.getSelectionModel().getSelectedItem();
        switch (ft) {
            case SERVICE_NAME:
                itemsCache.stream().filter((object) -> (object.getInterfaceFullName().toLowerCase().contains(filter.toLowerCase()))).forEachOrdered((object) -> {
                    items.add(object);
                });
                break;
            case APP_NAME:
                itemsCache.stream().filter((dsm) -> (dsm.getApplication().toLowerCase().contains(filter.toLowerCase()))).forEachOrdered((dsm) -> {
                    items.add(dsm);
                });
                break;
            case SERVER_IP:
                itemsCache.stream().filter((dsm) -> (dsm.getClientStr().contains(filter))).forEachOrdered((dsm) -> {
                    items.add(dsm);
                });
                break;
        }
    }
    mc.listViewStatusLabel.setText(String.format("共%d条,显示%d条", itemsCache.size(), items.size()));
    saveSetting();
}
 
Example 11
Source File: TestbedSidePanel.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void updateTests(ComboBoxModel<ListItem> model) {
  ObservableList<ListItem> list = tests.itemsProperty().get();
  list.clear();
  for (int i = 0; i < model.getSize(); i++) {
    list.add((ListItem) model.getElementAt(i));
  }
}
 
Example 12
Source File: UnSavedHistoryStage.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void onManageFavourites() {
    FavouriteHistoryStage favouriteHistoryStage = new FavouriteHistoryStage(new RunHistoryInfo("favourites"));
    favouriteHistoryStage.getStage().showAndWait();
    ObservableList<JSONObject> items = historyView.getItems();
    items.clear();
    items.addAll(runHistoryInfo.getTests());
}
 
Example 13
Source File: BrowserTab.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void setText(String listOfFiles) {
    ObservableList<File> items = getItems();
    items.clear();
    BufferedReader reader = new BufferedReader(new StringReader(listOfFiles));
    String line = null;
    try {
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (!line.equals("")) {
                items.add(new File(line));
            }
        }
    } catch (IOException e) {
    }
}
 
Example 14
Source File: ReportsController.java    From HealthPlus with Apache License 2.0 5 votes vote down vote up
public void fillPieChart(int months)
{
    ArrayList<ArrayList<String>> data = admin.lastMonthsReports(months);
    String[] test = {   
                        "Blood Grouping & Rh","Lipid Profile Test","LFT","RFT",
                        "HIV","CPK","Pathalogy Test",
                        "Complete Blood Count"
                    };
    ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(); 
    pieChartData.clear();
    int tmpSize = test.length;
    for(int i = 0; i < tmpSize; i++)
    {
        pieChartData.add(new PieChart.Data(test[i], Integer.parseInt(data.get(1).get(i))));
    }    
    
    pieChartData.forEach(data1 ->
            data1.nameProperty().bind(
                    Bindings.concat(
                            data1.getName(), " (", data1.pieValueProperty(), ")"
                    )
            )
    );
    
    labReportPieChart.setData(pieChartData);
    
    ArrayList<Integer> month = new ArrayList<Integer>();
    for (int i = 1; i < 13; i++)
    {
        month.add(i);
    }    
    //reportsCombo.getItems().clear();
    //reportsCombo.getItems().addAll(month);
    //reportsCombo.setValue(12);
    
}
 
Example 15
Source File: Machine.java    From CPUSim with GNU General Public License v3.0 4 votes vote down vote up
public void setEnd(End end) {
    ObservableList<Microinstruction> ends = microMap.get("end");
    ends.clear();
    ends.add(end);
}
 
Example 16
Source File: MainAction.java    From DevToolBox with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void serviceListClickAction() {
    DubboServiceModel item = (DubboServiceModel) mc.serviceList.getSelectionModel().getSelectedItem();
    if (item == null) {
        return;
    }
    try {
        saveSetting();
        DialogUtil.showDialog(mc.pane.getScene().getWindow());
        Task task = new Task() {
            @Override
            protected Object call() {
                try {
                    Platform.runLater(() -> {
                        mc.serviceMethods.getItems().clear();
                    });
                    ObservableList items = mc.providerIP.getItems();
                    items.clear();
                    String ip = item.getClientStr();
                    if (StringUtils.isBlank(ip)) {
                        DialogUtil.close();
                        return null;
                    }
                    if (CollectionUtils.isEmpty(item.getFullMethods(ip)) && item.getMethods(ip) != null) {
                        item.putFullMethods(ip, getAllMethods(item.getMethods(ip)));
                    }
                    Platform.runLater(() -> {
                        item.getUrlMap().entrySet().stream().map((entry) -> entry.getKey()).forEachOrdered((key) -> {
                            items.add(key);
                        });
                        mc.serviceMethods.getItems().addAll(item.getFullMethods(ip));
                        mc.providerIP.getSelectionModel().select(ip);
                        DialogUtil.close();
                    });
                } catch (Exception e) {
                    Toast.makeText("解析接口参数异常:" + e.getLocalizedMessage()).show(mc.pane.getScene().getWindow());
                    LOGGER.error(e.getLocalizedMessage(), e);
                    DialogUtil.close();
                }
                return null;
            }

            @Override
            protected void setException(Throwable t) {
                super.setException(t);
                Toast.makeText("解析接口参数异常:" + t.getLocalizedMessage()).show(mc.pane.getScene().getWindow());
                LOGGER.error(t.getLocalizedMessage(), t);
                DialogUtil.close();
            }
        };
        new Thread(task).start();
    } catch (Exception ex) {
        Toast.makeText("获取接口方法异常:" + ex.getLocalizedMessage()).show(mc.pane.getScene().getWindow());
        LOGGER.error(ex.getLocalizedMessage(), ex);
        DialogUtil.close();
    }
}
 
Example 17
Source File: StatusBarNotifier.java    From kafka-message-tool with MIT License 4 votes vote down vote up
private void resetStatusBarOnConstruction() {
    statusBar.getLeftItems().clear();
    final ObservableList<Node> rightItems = statusBar.getRightItems();
    rightItems.clear();
    doubleProperty = statusBar.progressProperty();
}
 
Example 18
Source File: CurveFittedAreaChartSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private static void smooth(ObservableList<PathElement> strokeElements, ObservableList<PathElement> fillElements) {
    // as we do not have direct access to the data, first recreate the list of all the data points we have
    final Point2D[] dataPoints = new Point2D[strokeElements.size()];
    for (int i = 0; i < strokeElements.size(); i++) {
        final PathElement element = strokeElements.get(i);
        if (element instanceof MoveTo) {
            final MoveTo move = (MoveTo) element;
            dataPoints[i] = new Point2D(move.getX(), move.getY());
        } else if (element instanceof LineTo) {
            final LineTo line = (LineTo) element;
            final double x = line.getX(), y = line.getY();
            dataPoints[i] = new Point2D(x, y);
        }
    }
    // next we need to know the zero Y value
    final double zeroY = ((MoveTo) fillElements.get(0)).getY();

    // now clear and rebuild elements
    strokeElements.clear();
    fillElements.clear();
    Pair<Point2D[], Point2D[]> result = calcCurveControlPoints(dataPoints);
    Point2D[] firstControlPoints = result.getKey();
    Point2D[] secondControlPoints = result.getValue();
    // start both paths
    strokeElements.add(new MoveTo(dataPoints[0].getX(), dataPoints[0].getY()));
    fillElements.add(new MoveTo(dataPoints[0].getX(), zeroY));
    fillElements.add(new LineTo(dataPoints[0].getX(), dataPoints[0].getY()));
    // add curves
    for (int i = 1; i < dataPoints.length; i++) {
        final int ci = i - 1;
        strokeElements.add(new CubicCurveTo(
                firstControlPoints[ci].getX(), firstControlPoints[ci].getY(),
                secondControlPoints[ci].getX(), secondControlPoints[ci].getY(),
                dataPoints[i].getX(), dataPoints[i].getY()));
        fillElements.add(new CubicCurveTo(
                firstControlPoints[ci].getX(), firstControlPoints[ci].getY(),
                secondControlPoints[ci].getX(), secondControlPoints[ci].getY(),
                dataPoints[i].getX(), dataPoints[i].getY()));
    }
    // end the paths
    fillElements.add(new LineTo(dataPoints[dataPoints.length - 1].getX(), zeroY));
    fillElements.add(new ClosePath());
}
 
Example 19
Source File: CurveFittedAreaChartSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private static void smooth(ObservableList<PathElement> strokeElements, ObservableList<PathElement> fillElements) {
    // as we do not have direct access to the data, first recreate the list of all the data points we have
    final Point2D[] dataPoints = new Point2D[strokeElements.size()];
    for (int i = 0; i < strokeElements.size(); i++) {
        final PathElement element = strokeElements.get(i);
        if (element instanceof MoveTo) {
            final MoveTo move = (MoveTo) element;
            dataPoints[i] = new Point2D(move.getX(), move.getY());
        } else if (element instanceof LineTo) {
            final LineTo line = (LineTo) element;
            final double x = line.getX(), y = line.getY();
            dataPoints[i] = new Point2D(x, y);
        }
    }
    // next we need to know the zero Y value
    final double zeroY = ((MoveTo) fillElements.get(0)).getY();

    // now clear and rebuild elements
    strokeElements.clear();
    fillElements.clear();
    Pair<Point2D[], Point2D[]> result = calcCurveControlPoints(dataPoints);
    Point2D[] firstControlPoints = result.getKey();
    Point2D[] secondControlPoints = result.getValue();
    // start both paths
    strokeElements.add(new MoveTo(dataPoints[0].getX(), dataPoints[0].getY()));
    fillElements.add(new MoveTo(dataPoints[0].getX(), zeroY));
    fillElements.add(new LineTo(dataPoints[0].getX(), dataPoints[0].getY()));
    // add curves
    for (int i = 1; i < dataPoints.length; i++) {
        final int ci = i - 1;
        strokeElements.add(new CubicCurveTo(
                firstControlPoints[ci].getX(), firstControlPoints[ci].getY(),
                secondControlPoints[ci].getX(), secondControlPoints[ci].getY(),
                dataPoints[i].getX(), dataPoints[i].getY()));
        fillElements.add(new CubicCurveTo(
                firstControlPoints[ci].getX(), firstControlPoints[ci].getY(),
                secondControlPoints[ci].getX(), secondControlPoints[ci].getY(),
                dataPoints[i].getX(), dataPoints[i].getY()));
    }
    // end the paths
    fillElements.add(new LineTo(dataPoints[dataPoints.length - 1].getX(), zeroY));
    fillElements.add(new ClosePath());
}
 
Example 20
Source File: ManagerFragment.java    From mdict-java with GNU General Public License v3.0 4 votes vote down vote up
public boolean try_read_configureLet(File newf) {
	try {
		BufferedReader in = new BufferedReader(new FileReader(newf));
		String line;
		int idx=0;
		ObservableList<mdict> mdModifying = tableView.getItems();
		mdModifying.clear();
		while((line = in.readLine())!=null){
			if(line.length()>0){
				boolean isFilter = false, disabled=false;
				if (line.startsWith("[:")) {
					int nextbrace=line.indexOf("]",2);
					if(nextbrace>=3){
						String[] args = line.substring(2, nextbrace).split(":");
						for (int i = 0; i < args.length; i++) {
							switch (args[i]){
								case "F":
									isFilter = true;
								break;
								case "D":
									disabled = true;
								break;
							}
						}
					}
					if(nextbrace!=-1)
						line = line.substring(nextbrace+1);
				}
				if(!PlainDictionaryPcJFX.windowPath.matcher(line).matches() && !line.startsWith("/"))
					line=opt.GetLastMdlibPath()+File.separator+line;
				if(disabled){
					rejector.add(line);
				}
				mdict mdTmp = mdict_cache.get(line);
				if(mdTmp==null)
					mdTmp=new_mdict_prempter(line, isFilter);
				mdModifying.add(mdTmp);
				idx++;
			}
		}
		in.close();
		return true;
	} catch (IOException e2) {
		e2.printStackTrace();
	}
	return false;
}