Skip to content

Commit

Permalink
#15: Basic support to remove a cluster instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Geisselmeier committed May 22, 2015
1 parent 2ef5f21 commit e9428f3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,20 @@ private void onAddInstance() {
});
}

protected void removeClusterInstance(StatusControl controlElement) {
controlElements.remove(controlElement);
settings.instances.remove(controlElement.getClusterInstance().serverNameProperty().getValue());
}


private void loadControlElements() {
settings.instances.forEach(instance -> {
controlElements.add(new StatusControl(new ClusterInstance(instance, settings.rules)));
controlElements.add(new StatusControl(new ClusterInstance(instance, settings.rules), this));
});
settings.instances.addListener((ListChangeListener<? super String>) change -> {
while (change.next()) {
change.getAddedSubList().forEach(added -> {
final StatusControl newInstance = new StatusControl(new ClusterInstance(added, settings.rules));
final StatusControl newInstance = new StatusControl(new ClusterInstance(added, settings.rules), this);
controlElements.add(newInstance);
runUpdateAsyn(newInstance);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import javafx.collections.ListChangeListener;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.CornerRadii;
Expand All @@ -18,7 +20,7 @@
import eu.hansolo.enzo.canvasled.Led;
import eu.hansolo.enzo.canvasled.LedBuilder;

public class StatusControl extends HBox {
public class StatusControl extends AnchorPane {

private final Led green = buildLed(Color.LAWNGREEN);

Expand All @@ -32,28 +34,52 @@ public class StatusControl extends HBox {

private final ClusterInstance instance;

private final ClusterHealthPaneController controller;

private final HBox middleBox = new HBox();

private final HBox innerBox = new HBox();

public StatusControl(ClusterInstance instance) {
private final Button removeBttn = new Button("x");

public StatusControl(ClusterInstance instance, ClusterHealthPaneController controller) {
this.instance = instance;
getChildren().add(innerBox);
this.controller = controller;
middleBox.getChildren().add(innerBox);
innerBox.getChildren().add(red);
innerBox.getChildren().add(yellow);
innerBox.getChildren().add(green);
innerBox.setMinWidth(USE_PREF_SIZE);
final LinearGradient gradient = new LinearGradient(0, 0, 1, 1, true, CycleMethod.NO_CYCLE, new Stop(0, Color.BLACK), new Stop(1, Color.DIMGRAY));
innerBox.setBackground(new Background(new BackgroundFill(gradient, new CornerRadii(15), null)));
innerBox.setPadding(new Insets(2, 5, 2, 5));
getChildren().add(instanceName);
setMaxHeight(USE_PREF_SIZE);
setMargin(innerBox, new Insets(0, 0, 0, 3));
setMargin(instanceName, new Insets(0, 5, 0, 10));
setAlignment(Pos.CENTER_LEFT);
middleBox.getChildren().add(instanceName);
middleBox.setMaxHeight(USE_PREF_SIZE);
HBox.setMargin(innerBox, new Insets(2, 0, 2, 3));
HBox.setMargin(instanceName, new Insets(0, 5, 0, 10));
middleBox.setAlignment(Pos.CENTER_LEFT);

middleBox.setBackground(new Background(new BackgroundFill(Color.WHITESMOKE, new CornerRadii(9), new Insets(-2))));
getChildren().add(middleBox);
AnchorPane.setLeftAnchor(middleBox, 0.0);
AnchorPane.setRightAnchor(middleBox, 0.0);
AnchorPane.setTopAnchor(middleBox, 0.0);
AnchorPane.setBottomAnchor(middleBox, 0.0);

setBackground(new Background(new BackgroundFill(Color.WHITESMOKE, new CornerRadii(9), new Insets(-2))));
getChildren().add(removeBttn);
AnchorPane.setRightAnchor(removeBttn, 0.0);

instanceName.setStyle("-fx-font-weight: bold;");
initBindings();

configureRemoveButton();
}

private void configureRemoveButton() {
removeBttn.setVisible(false);
setOnMouseEntered(evt -> removeBttn.setVisible(true));
setOnMouseExited(evt -> removeBttn.setVisible(false));
removeBttn.setOnAction(evt -> controller.removeClusterInstance(this));
}

public ClusterInstance getClusterInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,13 @@
import org.controlsfx.control.GridView;


/**
* Created by User: hansolo Date: 31.08.13 Time: 08:37
*/
public class StatusControlDemo extends Application {

private static final ClusterInstance instance1 = new ClusterInstance("localhost:61619", FXCollections.emptyObservableList());
private static final StatusControl control1 = new StatusControl(instance1);
private static final StatusControl control1 = new StatusControl(instance1, null);

private static final ClusterInstance instance2 = new ClusterInstance("jadice-server:61619", FXCollections.emptyObservableList());
private static final StatusControl control2 = new StatusControl(instance2);
private static final StatusControl control2 = new StatusControl(instance2, null);

private final Timer timer = new Timer();

Expand Down

0 comments on commit e9428f3

Please sign in to comment.