Ejemplo n.º 1
0
  public OperationDialog(
      CliGuiContext cliGuiCtx,
      ManagementModelNode node,
      String opName,
      String strDescription,
      ModelNode requestProperties) {
    super(cliGuiCtx.getMainWindow(), opName, Dialog.ModalityType.APPLICATION_MODAL);
    this.cliGuiCtx = cliGuiCtx;
    this.node = node;
    this.opName = opName;

    try {
      setProps(requestProperties);
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout(10, 10));

    // the html table allows word wrap and constant max width
    JLabel opDescription = new WordWrapLabel(strDescription, 400);
    JPanel opDescPanel = new JPanel();
    opDescPanel.add(opDescription);
    contentPane.add(opDescPanel, BorderLayout.NORTH);

    contentPane.add(makeInputPanel(), BorderLayout.CENTER);

    contentPane.add(makeButtonPanel(), BorderLayout.SOUTH);
    pack();
    setResizable(true);
  }
Ejemplo n.º 2
0
  private void setProps(ModelNode requestProperties) throws Exception {
    props = new TreeSet<RequestProp>();
    if (opName.equals("add")) {
      UserObject usrObj = (UserObject) node.getUserObject();
      props.add(
          new RequestProp(
              "/" + usrObj.getName() + "=<name>/",
              "Resource name for the new " + usrObj.getName(),
              true,
              ModelType.STRING));
    }

    if (opName.equals("write-attribute") && node.isLeaf()) {
      ModelNode nameNode = requestProperties.get("name");
      nameNode
          .get("type")
          .set(ModelType.UNDEFINED); // undefined type will display as uneditable String
      UserObject usrObj = (UserObject) node.getUserObject();
      ModelNode nameNodeValue = new ModelNode();
      nameNodeValue.set(usrObj.getName());
      props.add(new RequestProp("name", requestProperties.get("name"), nameNodeValue));

      ModelNode rscDesc =
          cliGuiCtx.getExecutor().doCommand(node.addressPath() + ":read-resource-description");
      ModelNode valueNode = rscDesc.get("result", "attributes", usrObj.getName());
      valueNode.get("required").set(false); // value is never required for write-attribute
      ModelNode valueNodeValue = usrObj.getBackingNode().get(usrObj.getName());
      props.add(new RequestProp("value", valueNode, valueNodeValue));
      return;
    }

    for (Property prop : requestProperties.asPropertyList()) {
      props.add(new RequestProp(prop.getName(), prop.getValue(), null));
    }
  }
Ejemplo n.º 3
0
  private String getJBossServerName() {
    String serverNamePrefix = "JBoss CLI / ";
    String serverNameCommand = "/:read-attribute(name=name,include-defaults=true)";
    if (!cliGuiCtx.isStandalone()) {
      serverNameCommand = "/host=*" + serverNameCommand;
    }

    try {
      ModelNode result = cliGuiCtx.getExecutor().doCommand(serverNameCommand);
      String outcome = result.get("outcome").asString();
      if (outcome.equals("success") && cliGuiCtx.isStandalone()) {
        return serverNamePrefix + result.get("result").asString();
      } else if (outcome.equals("success")) {
        return serverNamePrefix + result.get("result").asList().get(0).get("result").asString();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return serverNamePrefix + "<unknown>";
  }
Ejemplo n.º 4
0
  private OperationResponse execute(ModelNode request, boolean useWaitCursor) throws IOException {

    if (request.get(Util.OPERATION).asString().equals(Util.COMPOSITE)
        && (!request.get(Util.STEPS).isDefined() || request.get(Util.STEPS).asList().isEmpty())) {
      return OperationResponse.Factory.createSimple(
          new ModelNode(
              "WARN: no request was sent as there were no server-side operations to execute"));
    }

    try {
      if (useWaitCursor) {
        cliGuiCtx.getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      }
      return client.executeOperation(
          OperationBuilder.create(request).build(), OperationMessageHandler.DISCARD);
    } finally {
      if (useWaitCursor) {
        cliGuiCtx.getMainWindow().setCursor(Cursor.getDefaultCursor());
      }
    }
  }
Ejemplo n.º 5
0
  @Override
  public Map<String, JPanel> getTabs() {
    Map<String, JPanel> panelMap = new HashMap<String, JPanel>();

    final CommandContext cmdCtx;
    try {
      cmdCtx = CommandContextFactory.getInstance().newCommandContext();
      isConnected = connectCommandContext(cmdCtx);
      if (!isConnected) return panelMap;
    } catch (Exception e) {
      throw new RuntimeException("Error connecting to JBoss AS.", e);
    }

    cliGuiCtx = GuiMain.startEmbedded(cmdCtx);
    JPanel cliGuiPanel = cliGuiCtx.getMainPanel();

    jconsolePanel = new JPanel(new BorderLayout());
    jconsolePanel.add(GuiMain.makeMenuBar(cliGuiCtx), BorderLayout.NORTH);
    jconsolePanel.add(cliGuiPanel, BorderLayout.CENTER);

    panelMap.put(getJBossServerName(), jconsolePanel);
    return panelMap;
  }
Ejemplo n.º 6
0
 public CommandExecutor(CliGuiContext cliGuiCtx) {
   this.cliGuiCtx = cliGuiCtx;
   this.cmdCtx = cliGuiCtx.getCommmandContext();
   this.client = cmdCtx.getModelControllerClient();
   Runtime.getRuntime().addShutdownHook(new Thread(new ClientCloserShutdownHook()));
 }