private void loadServerConfigurations() {

    if (!hostSelection.isSet()) throw new RuntimeException("Host selection not set!");

    hostInfoStore.getServerConfigurations(
        hostSelection.getName(),
        new SimpleCallback<List<Server>>() {
          @Override
          public void onSuccess(List<Server> result) {
            getView().setConfigurations(hostSelection.getName(), result);
          }
        });
  }
  public void tryDelete(final Server server) {

    // check if instance exist
    ModelNode operation = new ModelNode();
    operation.get(ADDRESS).add("host", hostSelection.getName());
    operation.get(ADDRESS).add("server", server.getName());
    operation.get(OP).set(READ_RESOURCE_OPERATION);

    dispatcher.execute(
        new DMRAction(operation),
        new AsyncCallback<DMRResponse>() {

          @Override
          public void onFailure(Throwable throwable) {
            performDeleteOperation(server);
          }

          @Override
          public void onSuccess(DMRResponse result) {
            ModelNode response = result.get();
            String outcome = response.get(OUTCOME).asString();

            Boolean serverIsRunning = outcome.equals(SUCCESS) ? Boolean.TRUE : Boolean.FALSE;
            if (!serverIsRunning) performDeleteOperation(server);
            else
              Console.error(
                  "Failed to delete server configuration",
                  "The server instance is still running: " + server.getName());
          }
        });
  }
 public void loadProperties(final Server server) {
   hostInfoStore.loadProperties(
       hostSelection.getName(),
       server,
       new SimpleCallback<List<PropertyRecord>>() {
         @Override
         public void onSuccess(List<PropertyRecord> properties) {
           getView().setProperties(server.getName(), properties);
         }
       });
 }
  public void loadJVMConfiguration(final Server server) {
    hostInfoStore.loadJVMConfiguration(
        hostSelection.getName(),
        server,
        new SimpleCallback<Jvm>() {
          @Override
          public void onSuccess(Jvm jvm) {

            getView().setJvm(server.getName(), jvm);
          }
        });
  }
  @Override
  public void onDeleteJvm(String reference, Jvm jvm) {

    ModelNode address = new ModelNode();
    address.add("host", hostSelection.getName());
    address.add("server-config", reference);
    address.add(JVM, jvm.getName());

    DeleteJvmCmd cmd = new DeleteJvmCmd(dispatcher, factory, address);
    cmd.execute(
        new SimpleCallback<Boolean>() {
          @Override
          public void onSuccess(Boolean result) {
            loadServerConfigurations();
          }
        });
  }
  @Override
  public void onDeleteProperty(String reference, final PropertyRecord prop) {

    ModelNode address = new ModelNode();
    address.add("host", hostSelection.getName());
    address.add("server-config", reference);
    address.add("system-property", prop.getKey());

    DeletePropertyCmd cmd = new DeletePropertyCmd(dispatcher, factory, address);
    cmd.execute(
        prop,
        new SimpleCallback<Boolean>() {
          @Override
          public void onSuccess(Boolean result) {
            loadServerConfigurations();
          }
        });
  }
  @Override
  public void onUpdateJvm(String reference, String jvmName, Map<String, Object> changedValues) {

    if (changedValues.size() > 0) {
      ModelNode address = new ModelNode();
      address.add("host", hostSelection.getName());
      address.add("server-config", reference);
      address.add(JVM, jvmName);

      UpdateJvmCmd cmd = new UpdateJvmCmd(dispatcher, factory, propertyMetaData, address);
      cmd.execute(
          changedValues,
          new SimpleCallback<Boolean>() {
            @Override
            public void onSuccess(Boolean result) {
              loadServerConfigurations();
            }
          });
    }
  }
  private void performDeleteOperation(final Server server) {

    hostInfoStore.deleteServerConfig(
        hostSelection.getName(),
        server,
        new AsyncCallback<Boolean>() {
          @Override
          public void onFailure(Throwable caught) {
            Console.MODULES
                .getMessageCenter()
                .notify(
                    new Message(
                        "Failed to delete server config " + server.getName(),
                        Message.Severity.Error));
          }

          @Override
          public void onSuccess(Boolean wasSuccessful) {
            if (wasSuccessful) {
              Console.MODULES
                  .getMessageCenter()
                  .notify(new Message("Successfully deleted server config " + server.getName()));

              getEventBus().fireEvent(new StaleModelEvent(StaleModelEvent.SERVER_CONFIGURATIONS));

              loadServerConfigurations();
            } else {
              Console.MODULES
                  .getMessageCenter()
                  .notify(
                      new Message(
                          "Failed to delete server config " + server.getName(),
                          Message.Severity.Error));
            }
          }
        });
  }
  public void onSaveChanges(final Server entity, Map<String, Object> changedValues) {

    if (changedValues.size() > 0) {

      if (changedValues.containsKey("portOffset"))
        changedValues.put("socketBinding", entity.getSocketBinding());
      else if (changedValues.containsKey("socketBinding"))
        changedValues.put("portOffset", entity.getPortOffset());

      final String name = entity.getName();

      hostInfoStore.saveServerConfig(
          hostSelection.getName(),
          name,
          changedValues,
          new AsyncCallback<Boolean>() {

            @Override
            public void onFailure(Throwable caught) {
              // log and reset when something fails
              Console.error("Failed to modify server-config " + name);
              loadServerConfigurations();
            }

            @Override
            public void onSuccess(Boolean wasSuccessful) {
              if (wasSuccessful) {
                Console.info("Successfully modified server-config " + name);
              } else {
                Console.error("Failed to modify server-config " + name);
              }

              loadServerConfigurations();
            }
          });
    }
  }
 public String getSelectedHost() {
   return hostSelection.getName();
 }