コード例 #1
0
 private ObjectEditor createCodeObjectEditor() {
   final ObjectEditor objectEditor = new ObjectEditor();
   {
     StringPropertyEditor editor = new StringPropertyEditor();
     editor.setPropertyName("repositoryURL");
     editor.setLabel("代码仓库:");
     editor.addValidator(new NotEmptyValidator("代码仓库"));
     editor.setHelpContextID(HelpContextConstants.CONTEXT_JAE_APP_REPOSITORY);
     objectEditor.addPropertyEditor(editor);
   }
   return objectEditor;
 }
コード例 #2
0
  private ObjectEditor createAppInfoObjectEditor(
      final CloudInfo cloudInfo, final CloudApplication application) {
    final ObjectEditor objectEditor = new ObjectEditor();
    //		objectEditor.setLayout(new GridLayout(4, false));

    final int maxTotalMemory = cloudInfo.getLimits().getMaxTotalMemory();
    final int totalMemory = cloudInfo.getUsage().getTotalMemory();

    IValuechangeListener listener =
        new IValuechangeListener() {

          public void valuechanged(ValueChangeEvent event) {
            if (!(event.getSource() instanceof NumberPropertyEditor)) {
              return;
            }

            NumberPropertyEditor editor = (NumberPropertyEditor) event.getSource();
            if ("memory".equals(editor.getPropertyName())) {
              NumberPropertyEditor appCountEditor =
                  (NumberPropertyEditor) objectEditor.getPropertyEditor("appCount");
              int memory = (Integer) editor.getValue();
              int count = (Integer) appCountEditor.getValue();

              int maxAppCount =
                  (maxTotalMemory
                          - totalMemory
                          + application.getRunningInstances() * application.getMemory())
                      / memory;
              if (maxAppCount < count) appCountEditor.setValue(maxAppCount);
            } else if ("appCount".equals(editor.getPropertyName())) {
              NumberPropertyEditor memoryEditor =
                  (NumberPropertyEditor) objectEditor.getPropertyEditor("memory");
              int count = (Integer) editor.getValue();
              int memory = (Integer) memoryEditor.getValue();

              if (count <= 0) count = 1;
              int maxMemory =
                  (maxTotalMemory
                          - totalMemory
                          + application.getRunningInstances() * application.getMemory())
                      / count;
              if (maxMemory < memory) memoryEditor.setValue(maxMemory);
            }
          }
        };

    {
      NumberPropertyEditor editor = new NumberPropertyEditor(NumberType.INT);
      editor.setLabel("内存(M)");
      editor.setPropertyName("memory");
      editor.setIncrement(10);
      editor.setMinimum(128);
      int maxMemory =
          (maxTotalMemory
              - totalMemory
              + application.getRunningInstances() * application.getMemory());
      editor.setMaximum(maxMemory);
      editor.addValuechangeListener(listener);
      objectEditor.addPropertyEditor(editor);
    }
    {
      NumberPropertyEditor editor = new NumberPropertyEditor(NumberType.INT);
      editor.setLabel("实例数(个)");
      editor.setPropertyName("appCount");
      editor.setMinimum(1);
      int maxAppCount =
          (maxTotalMemory
                  - totalMemory
                  + application.getRunningInstances() * application.getMemory())
              / 128;
      editor.setMaximum(maxAppCount);
      editor.addValuechangeListener(listener);
      objectEditor.addPropertyEditor(editor);
    }
    return objectEditor;
  }