Esempio n. 1
0
  private void initGUI(final GUIInfo info) {
    // Prepare a value manager that will include all forms spanned in each
    // tab
    vm = new ValuesManager();

    // Create all the tabs each one for a specific setup step
    tabs = new TabSet();
    tabs.setWidth(500);
    tabs.setHeight(250);

    Tab registrationTab = setupRegistration(vm);
    Tab repositoryTab = setupRepository(vm);
    Tab databaseTab = setupDatabase(vm);
    Tab languageTab = setupLanguage(vm);
    Tab smtpTab = setupSmtp(vm);
    tabs.setTabs(registrationTab, repositoryTab, databaseTab, languageTab, smtpTab);

    // This is the button used to confirm each step
    submit = new IButton();
    submit.setTitle(I18N.message("next"));
    submit.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            onSubmit(info);
          }
        });

    // Prepare the heading panel with Logo and Title
    // Prepare the logo image to be shown inside the login form
    Label header = new Label(I18N.message("setup"));
    header.setStyleName("setupHeader");
    header.setIcon(Util.brandUrl("logo.png"));
    header.setIconWidth(205);
    header.setIconHeight(40);
    header.setHeight(45);

    // Prepare a panel to layout setup components
    VLayout layout = new VLayout();
    layout.setHeight(500);
    layout.setWidth(400);
    layout.setMembersMargin(5);
    layout.addMember(header);
    layout.addMember(tabs);
    layout.addMember(submit);

    // Panel for horizontal centering
    VLayout vPanel = new VLayout();
    vPanel.setDefaultLayoutAlign(Alignment.CENTER);
    vPanel.setWidth100();
    vPanel.setHeight(300);
    vPanel.addMember(layout);

    RootPanel.get().add(vPanel);

    // Remove the loading frame
    RootPanel.getBodyElement().removeChild(RootPanel.get("loadingWrapper").getElement());
  }
  public UpgradeLevelLayout(int x, int y) {

    this.setWidth(500);
    this.setHeight(300);
    this.setMembersMargin(5);
    this.setPadding(5);
    this.setBackgroundColor("#FFFFFF");
    this.setBorder("1px solid #CCCCCC");
    this.setOpacity(85);
    this.moveTo(x, y + 20);

    Label titleLabel = new Label("<b>User Levels:</b>");
    titleLabel.setIcon(CoreConstants.ICON_USER_INFO);
    titleLabel.setHeight(30);
    this.addMember(titleLabel);

    HTMLPane pane = new HTMLPane();
    pane.setWidth100();
    pane.setHeight100();
    pane.setOverflow(Overflow.AUTO);
    pane.setContentsURL("./documentation/user/user_levels.html");
    pane.setContentsType(ContentsType.PAGE);
    this.addMember(pane);

    Label closeLabel = new Label("Close");
    closeLabel.setIcon(CoreConstants.ICON_CLOSE);
    closeLabel.setHeight(25);
    closeLabel.setWidth100();
    closeLabel.setAlign(Alignment.RIGHT);
    closeLabel.setCursor(Cursor.HAND);
    closeLabel.addClickHandler(
        new ClickHandler() {

          @Override
          public void onClick(ClickEvent event) {
            destroy();
          }
        });

    this.addMember(closeLabel);
  }
  Canvas build() {
    VLayout vl = new VLayout();
    vl.setOverflow(Overflow.AUTO);

    this.label = new Label("No node selected");
    this.label.setWidth100();
    this.label.setAlign(Alignment.CENTER);

    this.nodeDetails = new DetailViewer();
    this.nodeDetails.setWidth100();
    this.nodeDetails.setHeight100();
    this.nodeDetails.setCanSelectText(true);
    DetailViewerField d1 = new DetailViewerField("nodeUrl", "URL");
    DetailViewerField d2 = new DetailViewerField("nodeState", "Status");
    DetailViewerField d3 = new DetailViewerField("nodeProvider", "Provider");
    DetailViewerField d4 = new DetailViewerField("nodeOwner", "Used by");
    DetailViewerField d5 = new DetailViewerField("sourceName", "Source");
    DetailViewerField d6 = new DetailViewerField("hostName", "Host");
    DetailViewerField d7 = new DetailViewerField("vmName", "JVM");
    DetailViewerField d8 = new DetailViewerField("description", "Description");
    this.nodeDetails.setFields(d1, d5, d6, d2, d3, d4, d7, d8);
    this.nodeCanvas = new VLayout();
    this.nodeCanvas.setWidth100();
    this.nodeLabel = new Label("<h3>Node</h3>");
    this.nodeLabel.setIcon(RMImages.instance.node_add_16().getSafeUri().asString());
    this.nodeLabel.setHeight(16);
    this.nodeCanvas.addMember(this.nodeLabel);
    this.nodeCanvas.addMember(this.nodeDetails);
    this.nodeCanvas.hide();

    this.nsDetails = new DetailViewer();
    this.nsDetails.setWidth100();
    this.nsDetails.setHeight100();
    this.nsDetails.setCanSelectText(true);
    DetailViewerField n1 = new DetailViewerField("sourceName", "Node Source");
    DetailViewerField n2 = new DetailViewerField("description", "Description");
    DetailViewerField n3 = new DetailViewerField("nodeProvider", "Owner");
    DetailViewerField n4 = new DetailViewerField("hosts", "Hosts");
    DetailViewerField n5 = new DetailViewerField("nodes", "Nodes");
    this.nsDetails.setFields(n1, n2, n3, n4, n5);
    this.nsCanvas = new VLayout();
    this.nsCanvas.setWidth100();
    this.nsCanvas.setHeight100();
    Label nsl = new Label("<h3>Node Source</h3>");
    nsl.setHeight(16);
    nsl.setIcon(RMImages.instance.nodesource_16().getSafeUri().asString());
    this.nsCanvas.addMember(nsl);
    this.nsCanvas.addMember(this.nsDetails);
    this.nsCanvas.hide();

    this.hostDetails = new DetailViewer();
    this.hostDetails.setWidth100();
    this.hostDetails.setHeight100();
    this.hostDetails.setCanSelectText(true);
    DetailViewerField h1 = new DetailViewerField("hostName", "Host");
    DetailViewerField h2 = new DetailViewerField("nodes", "Nodes");
    this.hostDetails.setFields(h1, h2);
    this.hostCanvas = new VLayout();
    this.hostCanvas.setWidth100();
    this.hostLabel = new Label("<h3>Host</h3>");
    hostLabel.setHeight(16);
    hostLabel.setIcon(RMImages.instance.host_16().getSafeUri().asString());
    this.hostCanvas.addMember(hostLabel);
    this.hostCanvas.addMember(this.hostDetails);
    this.hostCanvas.hide();

    vl.setMembers(label, nodeCanvas, nsCanvas, hostCanvas);
    return vl;
  }
  private void build() {
    final VLayout layout = new VLayout();
    layout.setMargin(5);

    final VStack infraLayout = new VStack();
    infraLayout.setHeight(26);
    final Label infraLabel = new Label("Updating available Infrastructures and Policies");
    infraLabel.setIcon("loading.gif");
    infraLabel.setHeight(26);
    infraLabel.setAlign(Alignment.CENTER);
    infraLayout.addMember(infraLabel);

    final DynamicForm infraForm = new DynamicForm();
    infraForm.setEncoding(Encoding.MULTIPART);
    infraForm.setMethod(FormMethod.POST);
    infraForm.setAction(GWT.getModuleBaseURL() + "createnodesource");
    infraForm.setTarget("__hiddenFrame");

    infraLayout.addMember(infraForm);

    final Label label =
        new Label(
            "A Node Source is a combination of an Infrastructure, which defines how resources"
                + " will be acquired, and a Policy, that dictates when resources can be acquired.");
    label.setHeight(40);

    final HashMap<String, List<FormItem>> allForms = new HashMap<String, List<FormItem>>();

    controller.fetchSupportedInfrastructuresAndPolicies(
        new Runnable() {
          public void run() {

            infraSelect = new SelectItem("infra", "Infrastructure");
            infraSelect.setRequired(true);
            policySelect = new SelectItem("policy", "Policy");
            policySelect.setRequired(true);

            infraSelect.setWidth(300);
            policySelect.setWidth(300);

            HiddenItem name = new HiddenItem("nsName");
            HiddenItem callback = new HiddenItem("nsCallback");
            HiddenItem session = new HiddenItem("sessionId");

            ArrayList<FormItem> tmpAll = new ArrayList<FormItem>();
            tmpAll.add(name);
            tmpAll.add(callback);
            tmpAll.add(session);
            tmpAll.add(infraSelect);

            LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
            for (PluginDescriptor inf :
                controller.getModel().getSupportedInfrastructures().values()) {
              String shortName =
                  inf.getPluginName().substring(inf.getPluginName().lastIndexOf('.') + 1);
              values.put(inf.getPluginName(), shortName);

              List<Field> configurableFields = inf.getConfigurableFields();
              ArrayList<FormItem> forms = new ArrayList<FormItem>(configurableFields.size());
              for (Field f : configurableFields) {
                FormItem infra = null;
                if (f.isPassword()) {
                  infra = new PasswordItem(inf.getPluginName() + f.getName(), f.getName());
                } else if (f.isFile() || f.isCredential()) {
                  infra = new UploadItem(inf.getPluginName() + f.getName(), f.getName());
                  if (f.isCredential()) {
                    PickerIcon cred =
                        new PickerIcon(
                            new Picker(Images.instance.key_16().getSafeUri().asString()),
                            new FormItemClickHandler() {
                              @Override
                              public void onFormItemClick(FormItemIconClickEvent event) {
                                CredentialsWindow win = new CredentialsWindow();
                                win.show();
                              }
                            });
                    cred.setPrompt("Create a Credential file");
                    cred.setWidth(16);
                    cred.setHeight(16);
                    cred.setAttribute("hspace", 6);
                    infra.setIcons(cred);
                  }
                } else {
                  infra = new TextItem(inf.getPluginName() + f.getName(), f.getName());
                }
                infra.setValue(f.getValue());
                infra.setWidth(250);
                infra.setHint("<nobr>" + f.getDescription() + "</nobr>");
                forms.add(infra);
                tmpAll.add(infra);
              }
              allForms.put(inf.getPluginName(), forms);
            }
            infraSelect.setValueMap(values);

            tmpAll.add(new SpacerItem());
            values.clear();
            tmpAll.add(policySelect);
            for (PluginDescriptor inf : controller.getModel().getSupportedPolicies().values()) {
              String shortName =
                  inf.getPluginName().substring(inf.getPluginName().lastIndexOf('.') + 1);
              values.put(inf.getPluginName(), shortName);

              List<Field> configurableFields = inf.getConfigurableFields();
              ArrayList<FormItem> forms = new ArrayList<FormItem>(configurableFields.size());
              for (Field f : configurableFields) {
                FormItem pol = null;
                if (f.isPassword()) {
                  pol = new PasswordItem(inf.getPluginName() + f.getName(), f.getName());
                } else if (f.isFile() || f.isCredential()) {
                  pol = new UploadItem(inf.getPluginName() + f.getName(), f.getName());
                  if (f.isCredential()) {
                    PickerIcon cred =
                        new PickerIcon(
                            new Picker(Images.instance.key_16().getSafeUri().asString()),
                            new FormItemClickHandler() {
                              @Override
                              public void onFormItemClick(FormItemIconClickEvent event) {
                                CredentialsWindow win = new CredentialsWindow();
                                win.show();
                              }
                            });
                    cred.setPrompt("Create a Credential file");
                    cred.setWidth(16);
                    cred.setHeight(16);
                    cred.setAttribute("hspace", 6);
                    pol.setIcons(cred);
                  }
                } else {
                  pol = new TextItem(inf.getPluginName() + f.getName(), f.getName());
                }
                pol.setValue(f.getValue());
                pol.setWidth(250);
                pol.setHint("<nobr>" + f.getDescription() + "</nobr>");
                forms.add(pol);
                tmpAll.add(pol);
              }
              allForms.put(inf.getPluginName(), forms);
            }
            policySelect.setValueMap(values);

            infraSelectChanged =
                new Runnable() {
                  @Override
                  public void run() {
                    if (policySelect.getValueAsString() == null) {
                      return;
                    }

                    String nsName = infraSelect.getValueAsString();
                    if (oldInfra != null) {
                      for (FormItem f : allForms.get(oldInfra)) {
                        f.hide();
                      }
                    }
                    for (FormItem f : allForms.get(nsName)) {
                      f.show();
                    }

                    if (oldInfra == null) {
                      oldInfra = nsName;
                      policySelectChanged.run();
                    } else {
                      oldInfra = nsName;
                    }
                  }
                };

            policySelectChanged =
                new Runnable() {
                  @Override
                  public void run() {
                    if (infraSelect.getValueAsString() == null) {
                      return;
                    }

                    String policy = policySelect.getValueAsString();
                    if (oldPolicy != null) {
                      for (FormItem f : allForms.get(oldPolicy)) {
                        f.hide();
                      }
                    }
                    for (FormItem f : allForms.get(policy)) {
                      f.show();
                    }

                    if (oldPolicy == null) {
                      oldPolicy = policy;
                      infraSelectChanged.run();
                    } else {
                      oldPolicy = policy;
                    }
                  }
                };

            infraSelect.addChangedHandler(
                new ChangedHandler() {
                  public void onChanged(ChangedEvent event) {
                    infraSelectChanged.run();
                  }
                });

            policySelect.addChangedHandler(
                new ChangedHandler() {
                  public void onChanged(ChangedEvent event) {
                    policySelectChanged.run();
                  }
                });

            infraForm.setFields(tmpAll.toArray(new FormItem[tmpAll.size()]));
            infraLabel.hide();
            infraForm.show();

            for (List<FormItem> li : allForms.values()) {
              for (FormItem it : li) {
                it.hide();
              }
            }
          }
        },
        new Runnable() {
          @Override
          public void run() {
            window.hide();
          }
        });

    final TextItem nameItem = new TextItem("nsName", "Name");
    DynamicForm nameForm = new DynamicForm();
    nameForm.setFields(nameItem);

    HLayout buttons = new HLayout();

    buttons.setWidth100();
    buttons.setHeight(22);
    buttons.setMargin(5);
    buttons.setAlign(Alignment.RIGHT);
    buttons.setMembersMargin(5);

    final IButton okButton = new IButton("Ok");
    okButton.setIcon(Images.instance.ok_16().getSafeUri().asString());
    okButton.setShowDisabledIcon(false);
    final IButton cancelButton = new IButton("Cancel");
    cancelButton.setIcon(Images.instance.cancel_16().getSafeUri().asString());
    cancelButton.setShowDisabledIcon(false);

    okButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            infraForm.setValue("infra", infraSelect.getValueAsString());
            infraForm.setValue("nsName", nameItem.getValueAsString());
            infraForm.setValue("policy", policySelect.getValueAsString());
            infraForm.setValue("sessionId", LoginModel.getInstance().getSessionId());
            infraForm.setCanSubmit(true);

            /* this smartGWT form looks nice but cannot do callbacks ;
             * we register a native JS function to the document, send it to
             * the servlet so that it writes it back when returning
             * when the browser reads the return value and interprets it as JS,
             * the callback is called */
            infraForm.setValue(
                "nsCallback",
                JSUtil.register(
                    new JSUtil.JSCallback() {
                      public void execute(JavaScriptObject obj) {
                        JSONObject js = new JSONObject(obj);
                        if (js.containsKey("result")
                            && js.get("result").isBoolean().booleanValue()) {
                          window.hide();
                          LogModel.getInstance()
                              .logMessage(
                                  "Successfully created nodesource: "
                                      + nameItem.getValueAsString());
                        } else {
                          String msg;
                          if (js.get("errorMessage").isString() != null) {
                            msg = js.get("errorMessage").isString().stringValue();
                          } else {
                            msg = js.toString();
                          }
                          label.setContents(
                              "<span style='color:red'>Failed to create Node Source :<br>"
                                  + msg
                                  + "</span>");
                          LogModel.getInstance()
                              .logImportantMessage(
                                  "Failed to create nodesource "
                                      + nameItem.getValueAsString()
                                      + ": "
                                      + msg);
                          layout.scrollToTop();
                        }
                        infraLabel.hide();
                        infraForm.show();
                        okButton.setDisabled(false);
                        cancelButton.setDisabled(false);
                      }
                    }));
            infraForm.submitForm();

            cancelButton.setDisabled(true);
            okButton.setDisabled(true);

            infraLabel.setContents("Node Source creation requested...");
            infraLabel.show();
            infraForm.hide();
          }
        });
    cancelButton.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            window.hide();
          }
        });
    buttons.setMembers(okButton, cancelButton);

    VLayout scroll = new VLayout();
    scroll.setHeight100();
    scroll.setWidth100();
    scroll.setMembers(infraLayout);
    scroll.setOverflow(Overflow.AUTO);
    scroll.setBorder("1px solid #ddd");
    scroll.setBackgroundColor("#fafafa");

    layout.addMember(label);
    layout.addMember(nameForm);
    layout.addMember(scroll);
    layout.addMember(buttons);

    int winWidth = com.google.gwt.user.client.Window.getClientWidth() * 80 / 100;
    int winHeight = com.google.gwt.user.client.Window.getClientHeight() * 80 / 100;
    winWidth = Math.min(1000, winWidth);
    winHeight = Math.min(1000, winHeight);

    this.window = new Window();
    this.window.setTitle("Create Node Source");
    this.window.setShowMinimizeButton(false);
    this.window.setIsModal(true);
    this.window.setShowModalMask(true);
    this.window.addItem(layout);
    this.window.setWidth(winWidth);
    this.window.setHeight(winHeight);
    this.window.setCanDragResize(true);
    this.window.setCanDragReposition(true);
    this.window.centerInPage();
  }