Commit 7ebf0e7d authored by legoc's avatar legoc

Added Search Instance

parent 8c02715c
......@@ -3,19 +3,32 @@
*/
package fr.ill.ics.n3d.gui;
import java.util.HashMap;
import fr.ill.ics.n3d.Nomad3DEditor;
import fr.ill.ics.n3d.model.Component;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;
import javafx.scene.control.TreeCell;
import javafx.scene.control.TreeView;
import javafx.scene.control.cell.CheckBoxTreeCell;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Callback;
import javafx.scene.control.Tooltip;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
/**
* @author dages
......@@ -80,6 +93,96 @@ public class HierarchyCell extends CheckBoxTreeCell<Component> {
});
rigthClickMenu.getItems().add(displayAllTheComponentsItem);
MenuItem searchItem = new MenuItem("Search Instance");
searchItem.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent t) {
String componentName = getItem().getName();
///////////////////////////////////////////////////////////////////////////////////
// Instance
Label instanceLabel = new Label(componentName);
HashMap<String, Integer> componentNames = Nomad3DEditor.getInstance().getModel().getComponentNames();
ObservableList<Integer> instances = FXCollections.observableArrayList();
if (componentNames.containsKey(getItem().getName())) {
int counter = componentNames.get(componentName);
for (int i = 1; i <= counter; ++i) {
instances.add(i);
}
}
ComboBox<Integer> instanceBox = new ComboBox<Integer>(instances);
instanceBox.getSelectionModel().select(0);
///////////////////////////////////////////////////////////////////////////////////
// Layout
GridPane scenePane = new GridPane();
scenePane.setAlignment(Pos.CENTER);
Scene scene = new Scene(scenePane);
Stage stage = new Stage(StageStyle.UTILITY);
stage.setTitle("Search");
stage.setScene(scene);
stage.initOwner(Nomad3DEditor.getInstance().getStage());
GridPane mainPane = new GridPane();
mainPane.setVgap(5);
mainPane.setHgap(10);
mainPane.setAlignment(Pos.CENTER);
scenePane.addRow(0, mainPane);
GridPane.setMargin(mainPane, new Insets(10));
GridPane addPane = new GridPane();
addPane.setVgap(5);
addPane.setHgap(10);
addPane.setAlignment(Pos.CENTER);
scenePane.addRow(0, addPane);
GridPane.setMargin(addPane, new Insets(10));
addPane.addRow(0, instanceLabel, instanceBox);
Button okButton = new Button("OK");
okButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
int instance = instanceBox.getSelectionModel().getSelectedItem();
Component component = Nomad3DEditor.getInstance().getModel().findComponentInstance(componentName, instance);
component.getTreeItem().selectedProperty().set(true);
// Close the stage.
stage.close();
}
});
Button cancelButton = new Button("Cancel");
cancelButton.setCancelButton(true);
cancelButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
stage.close();
}
});
GridPane buttonPane = new GridPane();
buttonPane.setHgap(10);
buttonPane.setAlignment(Pos.CENTER);
buttonPane.addRow(0, okButton, cancelButton);
mainPane.addRow(0, addPane);
mainPane.addRow(1, buttonPane);
stage.showAndWait();
}
});
rigthClickMenu.getItems().add(searchItem);
}
private String getTextValue(Component component) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment