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

The following examples show how to use javafx.collections.ObservableList#remove() . 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: TestCollectionController.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void deleteTestCase(LiveTestCase tc) {
    ObservableList<LiveTestCase> items = testsListView.getItems();
    int idx = items.indexOf(tc);

    if (idx >= 0) {
        items.remove(idx);
        if (!tc.isFrozen()) {
            unloadTestCase();

            if (!items.isEmpty()) {
                if (idx == 0) {
                    loadTestCase(0);
                } else {
                    loadTestCase(idx - 1);
                }
            }
        }
    }
}
 
Example 2
Source File: TabDockingContainer.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override
public void replace(Node base, INewDockingContainer indc) {
    ObservableList<Tab> tabs = getTabs();
    Tab found = null;
    for (Tab tab : tabs) {
        if (tab.getContent() == base) {
            found = tab;
            break;
        }
    }
    if (found != null) {
        int index = tabs.indexOf(found);
        tabs.remove(index);
        found.setContent(indc.get());
        tabs.add(index, found);
    }
}
 
Example 3
Source File: ListBindText.java    From EasyBind with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void test() {
    ObservableList<String> source = FXCollections.observableArrayList();
    source.addAll("a", "b", "c");

    ObservableList<String> target = FXCollections.observableArrayList();
    Subscription sub = EasyBind.listBind(target, source);

    assertEquals(source, target);

    source.addAll(2, Arrays.asList("b", "a"));
    assertEquals(Arrays.asList("a", "b", "b", "a", "c"), target);

    source.remove(1, 3);
    assertEquals(Arrays.asList("a", "a", "c"), target);

    sub.unsubscribe();
    source.add("d");
    assertEquals(Arrays.asList("a", "a", "c"), target);
}
 
Example 4
Source File: NodeTree.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
/**
 * Notify about removing the element.
 *
 * @param parent the parent
 * @param child  the child
 */
@FxThread
public void notifyRemoved(@Nullable final Object parent, @NotNull final Object child) {

    final TreeItem<TreeNode<?>> treeItem = tryToFindItem(parent, child);
    if (treeItem == null) {
        return;
    }

    final TreeItem<TreeNode<?>> parentItem = treeItem.getParent();
    final TreeNode<?> parentNode = parentItem.getValue();
    final TreeNode<?> node = treeItem.getValue();

    final ObservableList<TreeItem<TreeNode<?>>> children = parentItem.getChildren();
    parentNode.notifyChildPreRemove(node);
    children.remove(treeItem);
    parentNode.notifyChildRemoved(node);

    if (parentItem.isExpanded() && children.isEmpty()) {
        parentItem.setExpanded(false);
    }
}
 
Example 5
Source File: CSSFXMonitor.java    From cssfx with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    ObservableList<String> cssURIs = cssURIsWeak.get();

    if(cssURIs != null) {
        Runnable task = () -> {
            int counter = 0;
            while(counter < cssURIs.size()) {
                String v = cssURIs.get(counter);
                if(v.equals(originalURI) || v.equals(sourceURI)) {
                    cssURIs.remove(counter);
                    cssURIs.add(counter, sourceURI);
                }
                counter += 1;
            }
        };
        // It's important that we are using runLater even when we are using the JavaFX Thread.
        // This way we make sure we are currently not running the ChangeListener
        // which would result in an Exception.
        Platform.runLater(task);
    }
}
 
Example 6
Source File: BsqDashboardView.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private void updateAveragePriceFields(TextField field90, TextFieldWithIcon field30, boolean isUSDField) {
    long average90 = updateAveragePriceField(field90, 90, isUSDField);
    long average30 = updateAveragePriceField(field30.getTextField(), 30, isUSDField);
    boolean trendUp = average30 > average90;
    boolean trendDown = average30 < average90;

    Label iconLabel = field30.getIconLabel();
    ObservableList<String> styleClass = iconLabel.getStyleClass();
    if (trendUp) {
        field30.setVisible(true);
        field30.setIcon(AwesomeIcon.CIRCLE_ARROW_UP);
        styleClass.remove("price-trend-down");
        styleClass.add("price-trend-up");
    } else if (trendDown) {
        field30.setVisible(true);
        field30.setIcon(AwesomeIcon.CIRCLE_ARROW_DOWN);
        styleClass.remove("price-trend-up");
        styleClass.add("price-trend-down");
    } else {
        iconLabel.setVisible(false);
    }
}
 
Example 7
Source File: ExtendedDemo.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private void setNightMode(boolean on) {
  String customTheme = CustomDemo.class.getResource("customTheme.css").toExternalForm();
  String darkTheme = CustomDemo.class.getResource("darkTheme.css").toExternalForm();
  ObservableList<String> stylesheets = workbench.getStylesheets();
  if (on) {
    stylesheets.remove(customTheme);
    stylesheets.add(darkTheme);
  } else {
    stylesheets.remove(darkTheme);
    stylesheets.add(customTheme);
  }
}
 
Example 8
Source File: TabSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the Icon when calling setModule().
 */
private void updateIcon() {
  Node iconNode = icon.get();
  ObservableList<Node> children = controlBox.getChildren();
  children.remove(0);
  children.add(0, iconNode);
  iconNode.getStyleClass().add("tab-icon");
}
 
Example 9
Source File: SceneManager.java    From houdoku with MIT License 5 votes vote down vote up
/**
 * Toggles the color stylesheet for ALL roots between light and night mode.
 */
public void toggleTheme() {
    boolean pre_night_mode_enabled = (boolean) config.getValue(Config.Field.NIGHT_MODE_ENABLED);
    boolean reader_only = (boolean) config.getValue(Config.Field.NIGHT_MODE_READER_ONLY);

    for (Parent root : roots.values()) {
        ObservableList<String> stylesheets = root.getStylesheets();

        // if reader_only is selected, we want to only change the stylesheet for the reader
        // page, but we still need to update the nightModeItem for every controller
        if (pre_night_mode_enabled || !reader_only
                || controllers.get(root).getClass() == ReaderController.class) {
            // toggle the color stylesheet for the root
            if (pre_night_mode_enabled) {
                stylesheets.remove(STYLESHEET_NIGHT);
                stylesheets.add(STYLESHEET_LIGHT);
            } else {
                stylesheets.remove(STYLESHEET_LIGHT);
                stylesheets.add(STYLESHEET_NIGHT);
            }
        }

        // toggle the CheckMenuItem
        Controller controller = controllers.get(root);
        if (controller.nightModeItem != null) {
            controller.nightModeItem.setSelected(!pre_night_mode_enabled);
        }
    }

    // update field in config and save it
    config.replaceValue(Config.Field.NIGHT_MODE_ENABLED, !pre_night_mode_enabled);
    saveConfig();
}
 
Example 10
Source File: DesktopPane.java    From desktoppanefx with Apache License 2.0 5 votes vote down vote up
public DesktopPane removeInternalWindow(InternalWindow internalWindow) {
    ObservableList<Node> windows = internalWindowContainer.getChildren();
    if (internalWindow != null && windows.contains(internalWindow)) {
        internalWindows.remove(internalWindow);
        windows.remove(internalWindow);
        internalWindow.setDesktopPane(null);
    }

    return this;
}
 
Example 11
Source File: SongsController.java    From MusicPlayer with MIT License 5 votes vote down vote up
@Override
public void play() {
	
	Song song = selectedSong;
    ObservableList<Song> songList = tableView.getItems();
    if (MusicPlayer.isShuffleActive()) {
    	Collections.shuffle(songList);
    	songList.remove(song);
    	songList.add(0, song);
    }
    MusicPlayer.setNowPlayingList(songList);
    MusicPlayer.setNowPlaying(song);
    MusicPlayer.play();
}
 
Example 12
Source File: NowPlayingController.java    From MusicPlayer with MIT License 5 votes vote down vote up
@Override
public void play() {
	
	Song song = selectedSong;
    ObservableList<Song> songList = tableView.getItems();
    if (MusicPlayer.isShuffleActive()) {
    	Collections.shuffle(songList);
    	songList.remove(song);
    	songList.add(0, song);
    }
    MusicPlayer.setNowPlayingList(songList);
    MusicPlayer.setNowPlaying(song);
    MusicPlayer.play();
}
 
Example 13
Source File: DateTimeRangeInputPane.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Set the highlighting of the TitlePane's title.
 * <p>
 * Highlighting is done by adding/removing our own style class. We attempt
 * to make sure that we don't add it more than once.
 *
 * @param highlight True to be highlighted, false to be unhighlighted.
 */
private void setUsingAbsolute(final boolean highlight) {
    final ObservableList<String> classes = absPane.getStyleClass();
    if (highlight) {
        if (!classes.contains(HIGHLIGHTED_CLASS)) {
            classes.add(0, HIGHLIGHTED_CLASS);
            clearRangeButtons();
        }
    } else {
        classes.remove(HIGHLIGHTED_CLASS);
    }
}
 
Example 14
Source File: AlbumsController.java    From MusicPlayer with MIT License 5 votes vote down vote up
@Override
public void play() {
	
	Song song = selectedSong;
    ObservableList<Song> songList = songTable.getItems();
    if (MusicPlayer.isShuffleActive()) {
    	Collections.shuffle(songList);
    	songList.remove(song);
    	songList.add(0, song);
    }
    MusicPlayer.setNowPlayingList(songList);
    MusicPlayer.setNowPlaying(song);
    MusicPlayer.play();
}
 
Example 15
Source File: DataPlot.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** Update drop-downs for devices based on current 'devices', 'x_device', 'y_devices' */
private void updateToolbar()
{
    // Select the current scan in list of scan menu items
    for (MenuItem scan_sel : scan_selector.getItems())
        if (scan_sel.getText().endsWith("#" + reader.getScanId()))
                ((RadioMenuItem)scan_sel).setSelected(true);

    final List<String> devices = scan_devices.get();

    // Update devices for X Axis
    updateDeviceMenus(x_device_selector, devices, x_device, this::selectXDevice);

    int i = y_device_selectors.size();
    while (i > y_devices.size())
        y_device_selectors.remove(--i);
    while (i < y_devices.size())
    {
        final MenuButton y_device_selector = new MenuButton("Value " + (1 + i++));
        y_device_selector.setTooltip(new Tooltip("Select device for value axis"));
        y_device_selectors.add(y_device_selector);
    }

    updateDeviceMenus(add_y_device, devices, null, dev -> addYDevice(dev));

    // Update devices for Values
    for (i=0; i<y_device_selectors.size(); ++i)
    {
        final int index = i;
        updateDeviceMenus(y_device_selectors.get(i), devices, y_devices.get(i),
                          dev -> selectYDevice(index, dev));
    }

    final ObservableList<Node> items = toolbar.getItems();
    items.remove(3,  items.size());
    items.addAll(y_device_selectors);
    items.add(add_y_device);
    if (y_devices.size() > 1)
        items.add(remove_y_device);
}
 
Example 16
Source File: PlaylistsController.java    From MusicPlayer with MIT License 5 votes vote down vote up
@Override
public void play() {
    Song song = selectedSong;
    ObservableList<Song> songs = selectedPlaylist.getSongs();
    if (MusicPlayer.isShuffleActive()) {
        Collections.shuffle(songs);
        songs.remove(song);
        songs.add(0, song);
    }
    MusicPlayer.setNowPlayingList(songs);
    MusicPlayer.setNowPlaying(song);
    MusicPlayer.play();
}
 
Example 17
Source File: CollectionUtils.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Computes the previous contents of the source {@link ObservableList}
 * before the given {@link javafx.collections.ListChangeListener.Change} was
 * applied.
 *
 * @param <E>
 *            The element type of the {@link ObservableList}.
 * @param change
 *            The {@link javafx.collections.ListChangeListener.Change} for
 *            which to compute the previous contents.
 * @return A newly created {@link List} that resembles the state of the
 *         source {@link ObservableList} before the change.
 */
public static <E> List<E> getPreviousContents(
		ListChangeListener.Change<E> change) {
	if (change instanceof AtomicChange) {
		return ((AtomicChange<E>) change).getPreviousContents();
	}

	ObservableList<E> currentList = change.getList();
	ObservableList<E> previousList = FXCollections
			.observableArrayList(currentList);

	// walk over elementary changes and record them in a list
	change.reset();
	List<ElementarySubChange<E>> changes = ListListenerHelperEx
			.getElementaryChanges(change);

	// undo the changes in reverse order
	for (int i = changes.size() - 1; i >= 0; i--) {
		ElementarySubChange<E> c = changes.get(i);
		int from = c.getFrom();
		int to = c.getTo();
		if (ElementarySubChange.Kind.ADD.equals(c.getKind())
				|| ElementarySubChange.Kind.REPLACE.equals(c.getKind())) {
			// remove added elements
			for (int j = to - 1; j >= from; j--) {
				previousList.remove(j);
			}
		}
		if (ElementarySubChange.Kind.REMOVE.equals(c.getKind())
				|| ElementarySubChange.Kind.REPLACE.equals(c.getKind())) {
			// add removed elements
			List<E> removed = c.getRemoved();
			previousList.addAll(from, removed);
		}
		if (ElementarySubChange.Kind.PERMUTATE.equals(c.getKind())) {
			// create sub list with old permutation
			int[] permutation = c.getPermutation();
			List<E> subList = new ArrayList<>(to - from);
			for (int j = from; j < to; j++) {
				int k = permutation[j - from];
				subList.add(currentList.get(k));
			}
			// insert sub list at correct position
			previousList.remove(from, to);
			previousList.addAll(from, subList);
		}
	}
	return previousList;
}
 
Example 18
Source File: PharmacistController.java    From HealthPlus with Apache License 2.0 4 votes vote down vote up
@FXML
private void issueBill()
{
    String patient = patientSearchValue.getText(); 
    String billValue = billFee.getText();
    
    //("consultant_id slmc0001,patient_id hms0001pa,pharmacy_fee 0,discount 0,");
    String consultantID = "";
    if (searchTypePatientPharmacist.getSelectionModel().getSelectedItem() != null )
    {    
        String selectedValue = searchTypePatientPharmacist.getSelectionModel().getSelectedItem().toString();

        ArrayList<ArrayList<String>> prescriptionData = new ArrayList<>();
        String searchValue = patientSearchValue.getText();
        if (!searchValue.equals(""))
        {    
            searchTypePatientPharmacist.setStyle("-fx-border-color: #999 #999 #999 #999;");
            patientSearchValue.setStyle("-fx-border-color: #999 #999 #999 #999;");
            switch (selectedValue) 
            {
                case "Patient ID":
                    //System.out.println("testing1");
                    prescriptionData = pharmacist.getPrescribedDoc(searchValue);
                    consultantID = prescriptionData.get(1).get(0);
                    break;
                case "Name":
                    //System.out.println("testing2");
                    //patientData = pharmacist.getPrescriptionInfo(searchValue);
                    break;
                case "NIC":
                    //System.out.println("testing3");
                    //patientData = pharmacist.getPrescriptionInfo(searchValue);
                    break;
                default:
                    break;
            }
 
        }
        else
        {
            patientSearchValue.setStyle("-fx-border-color: red;");
        }    
    }
    else
    {
        searchTypePatientPharmacist.setStyle("-fx-border-color: red;");
    }
  
    
    if (! billValue.equals(""))
    {    
        String billInfo = "consultant_id "+ consultantID+"," + "patient_id " + patient + ",pharmacy_fee " + billValue;      
        boolean success = pharmacist.bill(billInfo,patient,billValue);

        if (success == true) 
        {
            showSuccessIndicator();
            patientSearchValue.setText("");
            patientSearchValue.setText(""); 
            billFee.setText("");
            billDate.setText("");
            
            ObservableList<String> empty = view.getTargetItems();
            int tmpSize = empty.size();
            for (int i = 0; i < tmpSize; i++ )
            {
                empty.remove(i);
                tmpSize--; i--;
            }

            ObservableList<String> empty2 = view.getSourceItems();
            tmpSize = empty2.size();
            for (int i = 0; i < tmpSize; i++ )
            {
                empty2.remove(i);
                tmpSize--; i--;
            }
            
        }
        
    }
}
 
Example 19
Source File: MemoizationListTest.java    From ReactFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Test
public void test() {
    ObservableList<String> source = new LiveArrayList<>("1", "22", "333");
    IntegerProperty counter = new SimpleIntegerProperty(0);
    MemoizationList<Integer> memoizing = LiveList.map(source, s -> {
        counter.set(counter.get() + 1);
        return s.length();
    }).memoize();
    LiveList<Integer> memoized = memoizing.memoizedItems();
    List<Integer> memoMirror = new ArrayList<>();
    memoized.observeModifications(mod -> {
        memoMirror.subList(mod.getFrom(), mod.getFrom() + mod.getRemovedSize()).clear();
        memoMirror.addAll(mod.getFrom(), mod.getAddedSubList());
    });

    assertEquals(0, memoized.size());

    source.add("4444");
    assertEquals(Collections.emptyList(), memoized);
    assertEquals(0, memoMirror.size());
    assertEquals(0, counter.get());

    memoizing.get(2);
    assertEquals(Arrays.asList(3), memoized);
    assertEquals(Arrays.asList(3), memoMirror);
    assertEquals(1, counter.get());

    counter.set(0);
    memoizing.get(0);
    assertEquals(Arrays.asList(1, 3), memoized);
    assertEquals(Arrays.asList(1, 3), memoMirror);
    assertEquals(1, counter.get());

    counter.set(0);
    source.subList(2, 4).replaceAll(s -> s + s);
    assertEquals(Arrays.asList(1), memoized);
    assertEquals(Arrays.asList(1), memoMirror);
    assertEquals(0, counter.get());

    counter.set(0);
    memoizing.observeModifications(mod -> {
        if(mod.getAddedSize() == 3) { // when three items added
            mod.getAddedSubList().get(0); // force evaluation of the first
            mod.getAddedSubList().get(1); // and second one
            source.remove(0); // and remove the first element from source
        }
    });
    source.remove(1, 4);
    assertEquals(Arrays.asList(1), memoized);
    assertEquals(Arrays.asList(1), memoMirror);
    assertEquals(0, counter.get());
    source.addAll("22", "333", "4444");
    assertEquals(Arrays.asList(2, 3), memoized);
    assertEquals(Arrays.asList(2, 3), memoMirror);
    assertEquals(2, counter.get());

    assertEquals(Arrays.asList(2, 3, 4), memoizing);
    assertEquals(3, counter.get());
    assertEquals(Arrays.asList(2, 3, 4), memoized);
    assertEquals(Arrays.asList(2, 3, 4), memoMirror);
}
 
Example 20
Source File: SplitDockingContainer.java    From marathonv5 with Apache License 2.0 2 votes vote down vote up
@Override
public void replace(Node base, INewDockingContainer indc) {
    double[] dividerPositions = getDividerPositions();
    ObservableList<Node> items = getItems();
    int indexOf = items.indexOf(base);
    items.remove(indexOf);
    items.add(indexOf, indc.get());
    setDividerPositions(dividerPositions);
}