All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.puresoltechnologies.javafx.workspaces.menu.SwitchWorkspaceMenuItem Maven / Gradle / Ivy

package com.puresoltechnologies.javafx.workspaces.menu;

import java.io.File;
import java.io.IOException;
import java.util.Optional;

import com.puresoltechnologies.javafx.utils.ResourceUtils;
import com.puresoltechnologies.javafx.workspaces.Workspace;
import com.puresoltechnologies.javafx.workspaces.WorkspaceSettings;
import com.puresoltechnologies.javafx.workspaces.dialogs.WorkspaceSelectionDialog;

import javafx.scene.Node;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.stage.Stage;

public class SwitchWorkspaceMenuItem extends MenuItem {

    private static final Image icon;
    static {
	try {
	    icon = ResourceUtils.getImage(Workspace.class, "icons/FatCow_Icons16x16/arrow_switch.png");
	} catch (IOException e) {
	    throw new RuntimeException(e);
	}
    }
    private final Stage stage;

    public SwitchWorkspaceMenuItem(Stage stage) {
	super("Other _" + Workspace.getWorkspaceTerm() + "...", new ImageView(icon));
	this.stage = stage;
	initialize();
    }

    public SwitchWorkspaceMenuItem(Stage stage, String text, Node graphic) {
	super(text, graphic);
	this.stage = stage;
	initialize();
    }

    public SwitchWorkspaceMenuItem(Stage stage, String text) {
	super(text);
	this.stage = stage;
	initialize();
    }

    private void initialize() {
	setOnAction(event -> {
	    WorkspaceSelectionDialog dialog = new WorkspaceSelectionDialog();
	    Optional result = dialog.showAndWait();
	    if (result.isPresent()) {
		WorkspaceSettings workspaceSettings = new WorkspaceSettings();
		workspaceSettings.setRestarting(true);
		workspaceSettings.writeSettings();
		stage.close();
		event.consume();
	    }
	});
	Workspace.workspaceTermProperty().addListener((o, oldValue, newValue) -> {
	    setText("Other _" + newValue + "...");
	});

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy