Beispiel #1
0
  public OutputStream receiveUpload(String filename, String MIMEType) {
    mainTabs.setReadOnly(true);
    subTabs.setReadOnly(true);
    FileOutputStream fos = null; // Output stream to write to
    file = new File(filename);

    try {
      System.out.println(MIMEType);
      if (MIMEType.equalsIgnoreCase("text/plain")
          || MIMEType.equalsIgnoreCase(
              "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
          || MIMEType.equalsIgnoreCase("application/octet-stream")) {
        fos = new FileOutputStream(file);
      } else {
      }

    } catch (final java.io.FileNotFoundException e) {
      Label l = new Label("<h4 style='color:red'>" + e.getMessage() + "</h4>");
      l.setContentMode(Label.CONTENT_XHTML);
      expDetails.addComponent(l);
      e.printStackTrace();
      return null;
    } catch (final Exception e) {
      // Error while opening the file. Not reported here.
      e.printStackTrace();
      return null;
    }

    return fos; // Return the output stream to write to
  }
  /** @return the Panel containing input text fields */
  public Component createInputPanel() {

    Panel inputPanel = new Panel("Send Message");

    inputPanel.addComponent(createPanelLayout("App URL", urlTextField, "http://127.0.0.1:8080/"));
    inputPanel.addComponent(createPanelLayout("Phone #", phoneNoField, "94721345678"));
    inputPanel.addComponent(createPanelLayout("Message ", messageField, "Message Content"));

    Button sendButton = createSendMsgButton();
    inputPanel.addComponent(sendButton);
    final AbstractOrderedLayout content = (AbstractOrderedLayout) inputPanel.getContent();
    content.setSpacing(true);
    content.setComponentAlignment(sendButton, Alignment.BOTTOM_RIGHT);

    return inputPanel;
  }
  public SettingsLayout(String userName, MainPage mainPage) {
    this.mainPage = mainPage;
    this.userName = userName;

    WebApplicationContext context = (WebApplicationContext) mainPage.getContext();
    WebBrowser webBrowser = context.getBrowser();
    height = webBrowser.getScreenHeight() - 310;

    setMargin(true);
    setSpacing(true);
    vl.setMargin(true);
    vl.setSpacing(true);
    panelEmail.setWidth("100%");
    addComponent(hl);

    hl.setFirstComponent(panelEmail);
    hl.setSecondComponent(panelPassword);

    oldEmail.setValue(GeneralController.getEmailFromUserName(userName));
    oldEmail.setWidth("250");
    oldEmail.setReadOnly(false);

    newEmail.setWidth("250");
    newEmail.addValidator(new EmailValidator("Email должен содержать знак '@' и полный домен."));

    saveButton = new Button("Сохранить изменения");
    saveButton.setVisible(true);
    saveButton.setIcon(new ThemeResource("icons/32/save.png"));

    resetUserPasswordButton.setVisible(true);
    resetUserPasswordButton.setIcon(new ThemeResource("icons/32/group_key.png"));
    resetUserPasswordButton.addListener(this);

    oldEmailInscription.setReadOnly(true);
    panelEmail.addComponent(oldEmailInscription);
    panelEmail.addComponent(oldEmail);
    panelEmail.addComponent(newEmail);
    panelEmail.addComponent(saveButton);
    panelPassword.addComponent(label);
    panelPassword.addComponent(resetUserPasswordButton);

    panelEmail.setHeight(height);
    panelPassword.setHeight(height);

    saveButton.addListener(this);
  }
Beispiel #4
0
 public SelectWindow(
     float width,
     int units,
     Collection<T> items,
     T selectedItem,
     Resource icon,
     String caption,
     String message,
     String okButtonText,
     String cancelButtonText) {
   super();
   if (caption != null) {
     setCaption(caption);
   }
   if (icon != null) {
     setIcon(icon);
   }
   setWidth(width, units);
   setModal(true);
   setClosable(false);
   setResizable(false);
   setDraggable(false);
   VerticalLayout verticalLayout = new VerticalLayout();
   verticalLayout.setMargin(true);
   verticalLayout.setSpacing(true);
   setContent(verticalLayout);
   Label label = new Label(message);
   addComponent(label);
   mySelect = new Select(null, items);
   mySelect.setNullSelectionAllowed(false);
   mySelect.setValue(selectedItem != null ? selectedItem : items.iterator().next());
   mySelect.setWidth(100, Sizeable.UNITS_PERCENTAGE);
   addComponent(mySelect);
   Panel panel = new Panel();
   addComponent(panel);
   verticalLayout.setComponentAlignment(panel, Alignment.MIDDLE_RIGHT);
   panel.addStyleName("light");
   HorizontalLayout horizontalLayout = new HorizontalLayout();
   panel.setContent(horizontalLayout);
   horizontalLayout.setSpacing(true);
   verticalLayout.setComponentAlignment(panel, Alignment.MIDDLE_RIGHT);
   myCancelButton = new Button(cancelButtonText, this);
   panel.addComponent(myCancelButton);
   myOkButton = new Button(okButtonText, this);
   panel.addComponent(myOkButton);
 }
Beispiel #5
0
  public void uploadFailed(Upload.FailedEvent event) {

    // Log the failure on screen.
    if (event.getMIMEType().equals("")) {
      root.addComponent(
          new Label(
              "Uploading "
                  + event.getFilename()
                  + " of type '"
                  + event.getMIMEType()
                  + "' failed."));
    } else {
      root.addComponent(
          new Label(
              "Sorry Only files with txt or xlsx type is allowed to upload, ...Upload failed."));
    }
    getWindow().showNotification("Failed :-( !");
  }
  public LoginModule() {

    setMargin(true);
    setSpacing(true);
    grid.setSizeFull();
    grid.setSpacing(true);

    final TextField username = new TextField();
    username.setValue("username");
    username.setWidth("120px");
    username.setStyleName("small");
    grid.addComponent(username, 0, 0);

    final PasswordField password = new PasswordField();
    password.setValue("password");
    password.setWidth("120px");
    password.setStyleName("small");
    grid.addComponent(password, 0, 1);

    Button button = new Button("Login");
    button.setWidth("120px");
    button.setStyleName("small");
    button.addListener(
        new Button.ClickListener() {

          @Override
          public void buttonClick(ClickEvent event) {
            login.setUsername(username.getValue().toString());
            login.setPassword(password.getValue().toString());
            String user = login.getUsername();
            String pass = login.getPassword();
            // login.setResult(authLog.login(user, pass));
            boolean result = authLog.login(user, pass);
            if (result == true) {
              label.setCaption("Successfully Login");
            } else {
              label.setCaption("SQL Error");
            }
          }
        });
    grid.addComponent(button, 0, 2);
    panel.addComponent(grid);
    addComponent(panel);
    addComponent(label);
  }
    public ExpandedWindow(boolean decorations) {
      super("ExpandedWindow");
      this.decorations = decorations;

      Panel content = new Panel();
      content.setLayoutManager(new BorderLayout());
      TextBox textBox = new TextBox(TestUtils.downloadGPL(), TextBox.Style.MULTI_LINE);
      textBox.setLayoutData(BorderLayout.Location.CENTER);
      textBox.setReadOnly(true);
      content.addComponent(textBox);

      setComponent(content);

      setHints(
          this.decorations
              ? Arrays.asList(Hint.EXPANDED)
              : Arrays.asList(Hint.EXPANDED, Hint.NO_DECORATIONS));
    }
 private Panel addPanelMenu(Menu menu) {
   panel = new Panel();
   initComponents();
   for (int i = 1; i <= NUMBER_OF_SERVICE_DAYS; i++) {
     weekdayLabel = new Label(Weekday.getWeekday(i).toString());
     gridLayout.addComponent(locateLayoutWeek(weekdayLabel));
     for (MenuItem menuItem : menu.getItems().get(Weekday.getWeekday(i))) {
       ShowDayMenusPanel showDayMenusPanel =
           new ShowDayMenusPanel(menuItem.getDescription(), menuItem.getCost());
       showDayMenusPanel.setId(menuItem.getId());
       showDayMenusPanel.setWeekday(menuItem.getWeekday());
       currentWeekMenusPanels.add(showDayMenusPanel);
       gridLayout.addComponent(showDayMenusPanel);
       panel.addComponent(gridLayout);
     }
   }
   return panel;
 }
 @Override
 public void init(final WindowBasedTextGUI textGUI) {
   final Window mainWindow = new BasicWindow("Choose test");
   Panel contentArea = new Panel();
   contentArea.setLayoutManager(new LinearLayout(Direction.VERTICAL));
   contentArea.addComponent(
       new Button(
           "Centered window",
           new Runnable() {
             @Override
             public void run() {
               textGUI.addWindow(new CenteredWindow());
             }
           }));
   contentArea.addComponent(
       new Button(
           "Undecorated window",
           new Runnable() {
             @Override
             public void run() {
               textGUI.addWindow(new UndecoratedWindow());
             }
           }));
   contentArea.addComponent(
       new Button(
           "Undecorated + Centered window",
           new Runnable() {
             @Override
             public void run() {
               textGUI.addWindow(new UndecoratedCenteredWindow());
             }
           }));
   contentArea.addComponent(
       new Button(
           "Full-screen window",
           new Runnable() {
             @Override
             public void run() {
               textGUI.addWindow(new FullScreenWindow(true));
             }
           }));
   contentArea.addComponent(
       new Button(
           "Undecorated + Full-screen window",
           new Runnable() {
             @Override
             public void run() {
               textGUI.addWindow(new FullScreenWindow(false));
             }
           }));
   contentArea.addComponent(
       new Button(
           "Expanded window",
           new Runnable() {
             @Override
             public void run() {
               textGUI.addWindow(new ExpandedWindow(true));
             }
           }));
   contentArea.addComponent(
       new Button(
           "Undecorated + Expanded window",
           new Runnable() {
             @Override
             public void run() {
               textGUI.addWindow(new ExpandedWindow(false));
             }
           }));
   contentArea.addComponent(
       new Button(
           "Close",
           new Runnable() {
             @Override
             public void run() {
               mainWindow.close();
             }
           }));
   mainWindow.setComponent(contentArea);
   textGUI.addWindow(mainWindow);
 }
Beispiel #10
0
  @SuppressWarnings({"deprecation", "serial"})
  private void updateComponents(final User user) {
    if (container != null) {
      container.removeAllComponents();
    }
    container = new Panel();
    root = new Panel();
    root.setStyle(Reindeer.PANEL_LIGHT);
    container.setHeight("100%");
    container.setStyle(Reindeer.PANEL_LIGHT);
    setCompositionRoot(container);

    // Create the Form
    newExpForm = new Form();
    newExpForm.setCaption("New Experiment");
    newExpForm.setWriteThrough(false); // we want explicit 'apply'
    newExpForm.setInvalidCommitted(false); // no invalid values in data model
    // Determines which properties are shown, and in which order:
    expNameField = new TextField("Experiment Name:");
    expNameField.setStyle(Reindeer.TEXTFIELD_SMALL);
    expNameField.setRequired(true);
    expNameField.setRequiredError("EXPERIMENT NAME CAN NOT BE EMPTY!");
    expNameField.setWidth("350px");
    expNameField.setMaxLength(70);

    speciesField = new TextField("Species:");
    speciesField.setStyle(Reindeer.TEXTFIELD_SMALL);
    speciesField.setRequired(true);
    speciesField.setRequiredError("EXPERIMENT SPECIES CAN NOT BE EMPTY!");
    speciesField.setWidth("350px");
    speciesField.setMaxLength(70);

    sampleTypeField = new TextField("Sample Type:");
    sampleTypeField.setStyle(Reindeer.TEXTFIELD_SMALL);
    sampleTypeField.setRequired(true);
    sampleTypeField.setRequiredError("EXPERIMENT SAMPLE TYPE CAN NOT BE EMPTY!");
    sampleTypeField.setWidth("350px");
    sampleTypeField.setMaxLength(70);

    sampleProcessingField = new TextField("Sample Processing:");
    sampleProcessingField.setStyle(Reindeer.TEXTFIELD_SMALL);
    sampleProcessingField.setRequired(true);
    sampleProcessingField.setRequiredError("EXPERIMENT SAMPLE PROCESSING CAN NOT BE EMPTY!");
    sampleProcessingField.setWidth("350px");
    sampleProcessingField.setMaxLength(70);

    instrumentTypeField = new TextField("Instrument Type:");
    instrumentTypeField.setStyle(Reindeer.TEXTFIELD_SMALL);
    instrumentTypeField.setRequired(true);
    instrumentTypeField.setRequiredError("EXPERIMENT INSTURMENT TYPE CAN NOT BE EMPTY!");
    instrumentTypeField.setWidth("350px");
    instrumentTypeField.setMaxLength(70);

    fragModeField = new TextField("Frag Mode:");
    fragModeField.setStyle(Reindeer.TEXTFIELD_SMALL);
    fragModeField.setRequired(true);
    fragModeField.setRequiredError("EXPERIMENT FRAG MODE CAN NOT BE EMPTY!");
    fragModeField.setWidth("350px");
    fragModeField.setMaxLength(70);

    UploadedByNameField = new TextField("Uploaded By:");
    UploadedByNameField.setStyle(Reindeer.TEXTFIELD_SMALL);
    UploadedByNameField.setRequired(true);
    UploadedByNameField.setRequiredError("EXPERIMENT UPLOADED BY CAN NOT BE EMPTY!");
    UploadedByNameField.setValue(user.getUsername());
    UploadedByNameField.setEnabled(false);
    UploadedByNameField.setWidth("350px");
    UploadedByNameField.setMaxLength(70);

    emailField = new TextField("Email:");
    emailField.setStyle(Reindeer.TEXTFIELD_SMALL);
    emailField.setRequired(true);
    emailField.setValue(user.getEmail());
    emailField.setEnabled(false);
    emailField.setRequiredError("EXPERIMENT EMAIL CAN NOT BE EMPTY!");
    emailField.setWidth("350px");
    emailField.setMaxLength(70);

    descriptionField = new TextArea("Description:");
    descriptionField.setStyle(Reindeer.TEXTFIELD_SMALL);
    descriptionField.setRequired(true);
    descriptionField.setRequiredError("EXPERIMENT Description CAN NOT BE EMPTY!");
    descriptionField.setWidth("350px");
    descriptionField.setMaxLength(950);

    publicationLinkField = new TextField("Publication Link:");
    publicationLinkField.setStyle(Reindeer.TEXTFIELD_SMALL);
    publicationLinkField.setWidth("350px");
    publicationLinkField.setMaxLength(300);

    newExpForm.addField(Integer.valueOf(1), expNameField);
    newExpForm.addField(Integer.valueOf(2), descriptionField);

    newExpForm.addField(Integer.valueOf(3), speciesField);
    newExpForm.addField(Integer.valueOf(4), sampleTypeField);
    newExpForm.addField(Integer.valueOf(5), sampleProcessingField);
    newExpForm.addField(Integer.valueOf(6), instrumentTypeField);
    newExpForm.addField(Integer.valueOf(7), fragModeField);
    newExpForm.addField(Integer.valueOf(8), UploadedByNameField);
    newExpForm.addField(Integer.valueOf(9), emailField);
    newExpForm.addField(Integer.valueOf(10), publicationLinkField);

    // Add form to layout
    container.addComponent(newExpForm);

    Panel p = new Panel();
    Label l =
        new Label(
            "<h4 style='color:blue'>Or Update Existing Experiments !</h4><h4 style='color:blue'>For New Experiment Please Leave Experiment ID Blank!</h4><h4 style='color:blue'><strong style='color:red'>* </strong> For New Experiment Please Remember to Upload Protein file first!</h4>");
    l.setContentMode(Label.CONTENT_XHTML);
    p.addComponent(l);
    container.addComponent(p);

    // Create the Form
    Form existExpForm = new Form();
    existExpForm.setCaption("Exist Experiments");
    expList = eh.getExperiments(null);
    List<String> strExpList = new ArrayList<String>();
    for (ExperimentBean exp : expList.values()) {
      if (user.getEmail().equalsIgnoreCase("*****@*****.**")
          || exp.getEmail().equalsIgnoreCase(user.getEmail())) {
        String str = exp.getExpId() + "	" + exp.getName() + "	( " + exp.getUploadedByName() + " )";
        strExpList.add(str);
      }
    }
    select = new Select("Experiment ID", strExpList);
    select.setImmediate(true);
    select.addListener(
        new Property.ValueChangeListener() {
          @Override
          public void valueChange(ValueChangeEvent event) {
            Object o = select.getValue();
            if (o != null) {
              String str = select.getValue().toString();
              String[] strArr = str.split("\t");
              int id = (Integer.valueOf(strArr[0]));
              ExperimentBean expDet = expList.get(id);
              if (expDetails != null) {
                expDetails.removeAllComponents();

                if (expDet.getProteinsNumber() == 0) {
                  Label l = new Label("<h4 style='color:red'>1) Protein File is Missing</h4>");
                  l.setContentMode(Label.CONTENT_XHTML);
                  expDetails.addComponent(l);
                } else {
                  Label l = new Label("<h4 style='color:blue'>1) Protein File is Uploaded</h4>");
                  l.setContentMode(Label.CONTENT_XHTML);
                  expDetails.addComponent(l);
                }
                if (expDet.getFractionsNumber() == 0) {
                  Label l = new Label("<h4 style='color:red'>2) Fraction File is Missing</h4>");
                  l.setContentMode(Label.CONTENT_XHTML);
                  expDetails.addComponent(l);
                } else {
                  Label l = new Label("<h4 style='color:blue'>2) Fraction File Uploaded</h4>");
                  l.setContentMode(Label.CONTENT_XHTML);
                  expDetails.addComponent(l);
                }
                //                        if (expDet.getFractionRange() == 0) {
                //                            Label l = new Label("<h4 style='color:red'>3) Fraction
                // Range File is Missing</h4>");
                //                            l.setContentMode(Label.CONTENT_XHTML);
                //                            expDetails.addComponent(l);
                //                        } else {
                //                            Label l = new Label("<h4 style='color:blue'>3)
                // Fraction Range File Uploaded</h4>");
                //                            l.setContentMode(Label.CONTENT_XHTML);
                //                            expDetails.addComponent(l);
                //                        }
                if (expDet.getPeptidesNumber() == 0) {
                  Label l = new Label("<h4 style='color:red'>3) Peptides File is Missing</h4>");
                  l.setContentMode(Label.CONTENT_XHTML);
                  expDetails.addComponent(l);
                } else {
                  Label l = new Label("<h4 style='color:blue'>3) Peptides File Uploaded</h4>");
                  l.setContentMode(Label.CONTENT_XHTML);
                  expDetails.addComponent(l);
                }
              }
            } else {
              expDetails.removeAllComponents();
              Label labelDetails =
                  new Label(
                      "<h4 style='color:red;'>Please Select Experiment To Show the Details.</h4>");
              labelDetails.setContentMode(Label.CONTENT_XHTML);
              expDetails.addComponent(labelDetails);
            }
          }
        });
    select.setWidth("60%");
    existExpForm.addField(Integer.valueOf(1), select);

    // Add form to layout
    VerticalLayout vlo = new VerticalLayout();

    if (hslo != null) {
      vlo.removeComponent(hslo);
    }
    hslo = new HorizontalLayout();
    hslo.setSizeFull();
    hslo.addComponent(existExpForm);
    vlo.addComponent(hslo);
    if (removeExperimentLayout != null) {
      hslo.removeComponent(removeExperimentLayout);
    }
    removeExperimentLayout = this.getRemoveForm(user.getEmail());
    hslo.addComponent(removeExperimentLayout);
    hslo.setComponentAlignment(removeExperimentForm, Alignment.MIDDLE_CENTER);
    vlo.addComponent(hslo);
    container.addComponent(vlo);

    // Create the Upload component.

    upload = new Upload(null, this);
    upload.setStyleName("small");
    upload.setVisible(true);
    upload.setHeight("30px");
    upload.setButtonCaption("ADD / EDIT EXPERIMENT !");

    // *****************************************************
    upload.addListener(
        new Upload.StartedListener() {
          @SuppressWarnings("static-access")
          @Override
          public void uploadStarted(StartedEvent event) {
            try {

              Thread.currentThread().sleep(1000);
              Thread t =
                  new Thread(
                      new Runnable() {
                        @Override
                        public void run() {
                          pi.setVisible(true);
                        }
                      });
              t.start();
              t.join();
            } catch (InterruptedException e) {
            }

            mainTabs.setReadOnly(true);
            subTabs.setReadOnly(true);
          }
        });

    upload.addListener(
        new Upload.FinishedListener() {
          @Override
          public void uploadFinished(FinishedEvent event) {
            pi.setVisible(false);
            mainTabs.setReadOnly(false);
            subTabs.setReadOnly(false);
            file = new File(event.getFilename());
          }
        });

    // ***********************************

    upload.addListener((Upload.SucceededListener) this);
    upload.addListener((Upload.FailedListener) this);
    if (helpNote != null) {
      vlo.removeComponent(helpNote);
    }
    Label label =
        new Label(
            "<h4 style='color:red;'>Please upload proteins file first</h4><h4 style='color:red;'>Please upload proteins files in (.txt) format.</h4><h4 style='color:red;'>Upload fraction range file after upload protein fraction file.</h4><h4 style='color:red;'>Upload fraction range file in (.xlsx) format.</h4>");
    label.setContentMode(Label.CONTENT_XHTML);
    helpNote = help.getHelpNote(label);
    helpNote.setMargin(false, true, true, true);

    vlo.addComponent(upload);
    vlo.addComponent(pi);
    vlo.addComponent(helpNote);
    vlo.setComponentAlignment(helpNote, Alignment.MIDDLE_RIGHT);

    expDetails = new Panel("Experiment Details");
    Label labelDetails =
        new Label("<h4 style='color:red;'>Please Select Experiment To Show the Details.</h4>");
    labelDetails.setContentMode(Label.CONTENT_XHTML);
    expDetails.addComponent(labelDetails);

    vlo.addComponent(expDetails);
    root.addComponent(vlo);
    container.addComponent(root);
  }
  @Override
  public void init(WindowBasedTextGUI textGUI) {
    final BasicWindow window = new BasicWindow("Grid layout test");

    final Panel leftPanel = new Panel();

    Panel checkBoxPanel = new Panel();
    for (int i = 0; i < 4; i++) {
      CheckBox checkBox = new CheckBox("Checkbox #" + (i + 1));
      checkBoxPanel.addComponent(checkBox);
    }

    Panel textBoxPanel = new Panel();
    textBoxPanel.addComponent(
        Panels.horizontal(new Label("Normal:   "), new TextBox(new TerminalSize(12, 1), "Text")));
    textBoxPanel.addComponent(
        Panels.horizontal(
            new Label("Password: "******"Text").setMask('*')));

    Panel buttonPanel = new Panel();
    buttonPanel.addComponent(
        new Button(
            "Enable spacing",
            new Runnable() {
              @Override
              public void run() {
                LinearLayout layoutManager = (LinearLayout) leftPanel.getLayoutManager();
                layoutManager.setSpacing(layoutManager.getSpacing() == 0 ? 1 : 0);
              }
            }));

    leftPanel.addComponent(checkBoxPanel.withBorder(Borders.singleLine("CheckBoxes")));
    leftPanel.addComponent(textBoxPanel.withBorder(Borders.singleLine("TextBoxes")));
    leftPanel.addComponent(buttonPanel.withBorder(Borders.singleLine("Buttons")));

    Panel rightPanel = new Panel();
    textBoxPanel = new Panel();
    TextBox readOnlyTextArea = new TextBox(new TerminalSize(16, 8));
    readOnlyTextArea.setReadOnly(true);
    readOnlyTextArea.setText(TestUtils.downloadGPL());
    textBoxPanel.addComponent(readOnlyTextArea);
    rightPanel.addComponent(textBoxPanel.withBorder(Borders.singleLine("Read-only")));
    rightPanel.setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Fill));

    Panel contentArea = new Panel();
    contentArea.setLayoutManager(new LinearLayout(Direction.VERTICAL));
    contentArea.addComponent(Panels.horizontal(leftPanel, rightPanel));
    contentArea.addComponent(
        new Separator(Direction.HORIZONTAL)
            .setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Fill)));
    contentArea.addComponent(
        new Button(
                "OK",
                new Runnable() {
                  @Override
                  public void run() {
                    window.close();
                  }
                })
            .setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.Center)));
    window.setComponent(contentArea);
    textGUI.addWindow(window);
  }
  @Override
  public void attach() {
    super.attach();
    init(
        getBundleString("streamingConfigPanel.caption"),
        getComponentFactory().createGridLayout(1, 5, true, true));
    myVlcEnabled = getComponentFactory().createCheckBox("streamingConfigPanel.vlcEnabled");
    myVlcBinary =
        getComponentFactory()
            .createTextField(
                "streamingConfigPanel.vlcBinary",
                new VlcExecutableFileValidator(
                    getBundleString("streamingConfigPanel.vlcBinary.invalidBinary")));
    myVlcBinary.setImmediate(false);
    myVlcBinarySelect =
        getComponentFactory().createButton("streamingConfigPanel.vlcBinary.select", this);
    myVlcHomepageButton =
        getComponentFactory().createButton("streamingConfigPanel.vlcHomepage", this);
    myVlcForm = getComponentFactory().createForm(null, true);
    myVlcForm.addField(myVlcEnabled, myVlcEnabled);
    myVlcForm.addField(myVlcBinary, myVlcBinary);
    myVlcForm.addField(myVlcBinarySelect, myVlcBinarySelect);
    myVlcForm.addField(myVlcHomepageButton, myVlcHomepageButton);
    Panel vlcPanel =
        getComponentFactory()
            .surroundWithPanel(
                myVlcForm,
                FORM_PANEL_MARGIN_INFO,
                getBundleString("streamingConfigPanel.caption.vlc"));
    addComponent(vlcPanel);
    Panel transcoderPanel = new Panel(getBundleString("streamingConfigPanel.caption.transcoder"));
    transcoderPanel.setContent(getComponentFactory().createVerticalLayout(true, true));
    Panel addTranscoderButtons = new Panel();
    addTranscoderButtons.addStyleName("light");
    addTranscoderButtons.setContent(
        getApplication().getComponentFactory().createHorizontalLayout(false, true));
    myAddTranscoder =
        getComponentFactory().createButton("streamingConfigPanel.transcoder.add", this);
    addTranscoderButtons.addComponent(myAddTranscoder);
    myTranscoderTable = new Table();
    myTranscoderTable.setCacheRate(50);
    myTranscoderTable.addContainerProperty(
        "name",
        String.class,
        null,
        getBundleString("streamingConfigPanel.transcoder.name"),
        null,
        null);
    myTranscoderTable.addContainerProperty("edit", Button.class, null, "", null, null);
    myTranscoderTable.addContainerProperty("delete", Button.class, null, "", null, null);
    myTranscoderTable.setSortContainerPropertyId("name");
    transcoderPanel.addComponent(myTranscoderTable);
    transcoderPanel.addComponent(addTranscoderButtons);
    addComponent(transcoderPanel);
    myCacheForm = getComponentFactory().createForm(null, true);
    myTranscodingCacheMaxGiB =
        getComponentFactory()
            .createTextField(
                "streamingConfigPanel.cache.transcodingCacheMaxGiB",
                getApplication().getValidatorFactory().createMinMaxValidator(1, 1024));
    myCacheForm.addField("limitTranscoding", myTranscodingCacheMaxGiB);
    myHttpLiveStreamCacheMaxGiB =
        getComponentFactory()
            .createTextField(
                "streamingConfigPanel.cache.httpLiveStreamCacheMaxGiB",
                getApplication().getValidatorFactory().createMinMaxValidator(1, 1024));
    myCacheForm.addField("limitHttpLiveStream", myHttpLiveStreamCacheMaxGiB);
    myClearAllCachesButton =
        getComponentFactory().createButton("streamingConfigPanel.clearAllCaches", this);
    myCacheForm.addField(myClearAllCachesButton, myClearAllCachesButton);
    addComponent(
        getComponentFactory()
            .surroundWithPanel(
                myCacheForm,
                FORM_PANEL_MARGIN_INFO,
                getBundleString("streamingConfigPanel.caption.cache")));

    addDefaultComponents(0, 4, 0, 4, false);

    initFromConfig();
  }
  public ModalAddNewSender(final SenderList sl) {
    super();
    setClosable(false);
    setModal(true);
    setWidth("300px");

    Panel rootPanel = new Panel("Add new Sender");
    final VerticalLayout verticalLayout = new VerticalLayout();
    final TextField tfName = new TextField("Name");
    final TextField tfFromMail = new TextField("From E-Mail");
    final TextField tfReplyTo = new TextField("ReplyTo E-Mail");

    verticalLayout.addComponent(tfName);
    verticalLayout.addComponent(tfFromMail);
    verticalLayout.addComponent(tfReplyTo);

    HorizontalLayout buttonLayout = new HorizontalLayout();

    Button saveButton = new Button("Save");
    Button cancelButton = new Button("Cancel");

    cancelButton.addListener(
        new Button.ClickListener() {
          @Override
          public void buttonClick(Button.ClickEvent event) {
            event.getButton().getWindow().setVisible(false);
            event
                .getButton()
                .getWindow()
                .getParent()
                .removeComponent(event.getButton().getWindow());
          }
        });

    saveButton.addListener(
        new Button.ClickListener() {
          @Override
          public void buttonClick(Button.ClickEvent event) {
            if (tfName.getValue().equals("")) {
              tfName.setComponentError(new UserError("Name must not be empty"));
            } else {
              tfName.setComponentError(null);
            }

            if (tfFromMail.getValue().equals("")) {
              tfFromMail.setComponentError(new UserError("From E-Mail must not be empty"));
            } else {
              tfFromMail.setComponentError(null);
            }

            if (tfReplyTo.getValue().equals("")) {
              tfReplyTo.setComponentError(new UserError("Reply-To E-Mail must not be empty"));
            } else {
              tfReplyTo.setComponentError(null);
            }

            if (!tfName.getValue().equals("")
                && !tfFromMail.getValue().equals("")
                && !tfReplyTo.getValue().equals("")) {
              tfName.setComponentError(null);
              tfFromMail.setComponentError(null);
              tfReplyTo.setComponentError(null);

              long senderId = Util.generateId();
              try {
                Sender s =
                    new Sender(
                        senderId,
                        tfFromMail.getValue().toString(),
                        tfReplyTo.getValue().toString(),
                        tfName.getValue().toString());
                event.getButton().getWindow().setVisible(false);
                event
                    .getButton()
                    .getWindow()
                    .getParent()
                    .removeComponent(event.getButton().getWindow());
                event
                    .getButton()
                    .getWindow()
                    .getParent()
                    .showNotification("Saved successfully", Notification.TYPE_HUMANIZED_MESSAGE);
                sl.getBeanContainer().addItem(s.getId(), s);

                // The sender select could be placed anywhere but must be reloaded to reflect the
                // changes.
                SenderSelectBox.reloadSelect();
              } catch (RuntimeException e) {
                // Should never happen ... hopefully :D
              }
            }
          }
        });

    buttonLayout.setSpacing(true);
    buttonLayout.addComponent(saveButton);
    buttonLayout.addComponent(cancelButton);

    verticalLayout.addComponent(buttonLayout);
    rootPanel.addComponent(verticalLayout);
    this.addComponent(rootPanel);
  }
Beispiel #14
0
  private void buildWorkSpace() {
    mainLayout.addTab(workSpace, "Work Space");
    workSpace.setSizeFull();

    final TextField className = new TextField("Correlator Class Name");
    final TextArea classCode = new TextArea("Correlator Code");

    final TextField builderClassName = new TextField("Builder Class Name");
    final TextArea builderClassCode = new TextArea("Builder Code");

    final CheckBox withBuilder = new CheckBox("Correlator comes with builder?");
    withBuilder.setImmediate(true);
    withBuilder.addListener(
        new Property.ValueChangeListener() {
          public void valueChange(Property.ValueChangeEvent event) {
            if (withBuilder.booleanValue()) {
              builderClassName.setVisible(true);
              builderClassCode.setVisible(true);
            } else {
              builderClassName.setVisible(false);
              builderClassCode.setVisible(false);
            }
          }
        });

    final Button compile = new Button("Add Correlator");
    compile.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {

            if (!withBuilder.booleanValue()) {
              CorrelatorFromCodeFactory.createCorrelator(
                  (String) helper.getBean("classPath"),
                  className.getValue().toString(),
                  classCode.getValue().toString(),
                  correlatorBuilderManager,
                  feed,
                  correlatorPool,
                  null,
                  null,
                  null);
            } else {
              RuntimeJavaFileCompiler.compile(
                  (String) helper.getBean("classPath"),
                  className.getValue().toString(),
                  classCode.getValue().toString());
              CorrelatorBuilderFromCodeFactory.createCorrelatorBuilder(
                  (String) helper.getBean("classPath"),
                  builderClassName.getValue().toString(),
                  builderClassCode.getValue().toString(),
                  correlatorBuilderManager,
                  feed,
                  correlatorPool);
            }
          }
        });

    workSpace.addComponent(className);
    workSpace.addComponent(classCode);
    workSpace.addComponent(withBuilder);
    workSpace.addComponent(builderClassName);
    workSpace.addComponent(builderClassCode);
    builderClassName.setVisible(false);
    builderClassCode.setVisible(false);
    workSpace.addComponent(compile);

    classCode.setWidth("100%");
    classCode.setHeight("500px");
    builderClassCode.setWidth("100%");
    builderClassCode.setHeight("500px");
  }
Beispiel #15
0
  private void buildFeedControl() {
    mainLayout.addTab(feedControl, "Feed Management");
    feedControl.setSizeFull();

    HorizontalLayout h1 = new HorizontalLayout();
    final TextField feedPath = new TextField("Feeds Folder:");
    h1.addComponent(feedPath);
    final Button updateFeedPath = new Button("Update");
    h1.addComponent(updateFeedPath);
    h1.setComponentAlignment(updateFeedPath, Alignment.BOTTOM_RIGHT);
    feedControl.addComponent(h1);

    updateFeedPath.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            feed.reset();
            feedsPath = feedPath.getValue().toString();
            feed.setFeedsPath(feedsPath);
            buildFeedSelect();
          }
        });

    HorizontalLayout h2 = new HorizontalLayout();
    final Select pairSelect = buildPairSelect();
    h2.addComponent(pairSelect);
    h2.addComponent(feedSelect);
    final Button addPairFeed = new Button("Add");
    h2.addComponent(addPairFeed);
    h2.setComponentAlignment(addPairFeed, Alignment.BOTTOM_RIGHT);
    feedControl.addComponent(h2);

    addPairFeed.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            feed.addPairFeed((Pair) pairSelect.getValue(), feedSelect.getValue().toString());
          }
        });

    HorizontalLayout h3 = new HorizontalLayout();
    final TextField maxPopulation = new TextField("Maximum Population:");
    maxPopulation.setValue("200");
    h3.addComponent(maxPopulation);
    final Button updateMaxPop = new Button("Update");
    h3.addComponent(updateMaxPop);
    h3.setComponentAlignment(updateMaxPop, Alignment.BOTTOM_RIGHT);
    feedControl.addComponent(h3);

    updateMaxPop.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            correlatorPool.setMaxPopulation(Integer.parseInt(maxPopulation.getValue().toString()));
          }
        });

    final Button startSim = new Button("Start Learning");

    feedControl.addComponent(startSim);

    startSim.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            try {
              emulator.startEmulation();
              // emulator.run();
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });

    final Button endSim = new Button("End Learning");

    feedControl.addComponent(endSim);

    endSim.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            try {
              emulator.die();
              // emulator.stop();
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        });

    final Button pauseFeed = new Button("Pause Feed");

    feedControl.addComponent(pauseFeed);

    pauseFeed.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            feed.pause();
          }
        });

    final Button resumeFeed = new Button("Resume Feed");

    feedControl.addComponent(resumeFeed);

    resumeFeed.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            feed.resume();
          }
        });

    final Button testInit = new Button("Use Test Init");

    feedControl.addComponent(testInit);

    testInit.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            feed.reset();
            feedsPath = "C:\\Users\\Oblene\\Desktop\\Sandbox\\Data";
            // feedsPath = "/app/testing/hans/WebApps/Data";
            feed.setFeedsPath(feedsPath);
            buildFeedSelect();

            feed.addPairFeed(Pair.EURUSD, "EURUSD_5 Mins_Bid_2008.01.01_2012.12.31.csv");
            feed.addPairFeed(Pair.GBPUSD, "GBPUSD_5 Mins_Bid_2008.01.01_2012.12.31.csv");
            feed.addPairFeed(Pair.USDCHF, "USDCHF_5 Mins_Bid_2008.01.01_2012.12.31.csv");
            // feed.addPairFeed(Pair.USDJPY, "USDJPY_5 Mins_Bid_2008.01.01_2012.12.31.csv");
            feed.addPairFeed(Pair.AUDUSD, "AUDUSD_5 Mins_Bid_2008.01.01_2012.12.31.csv");
            feed.addPairFeed(Pair.NZDUSD, "NZDUSD_5 Mins_Bid_2008.01.01_2012.12.31.csv");
            feed.addCalendarFeed("Calendar_2008.csv");

            CorrelatorFromCodeFactory.createCorrelator(
                (String) helper.getBean("classPath"),
                "MovingAverageCorrelator",
                "import com.bluesmoke.farm.correlator.CorrelatorPool;\n"
                    + "import com.bluesmoke.farm.correlator.GenericCorrelator;\n"
                    + "import com.bluesmoke.farm.correlator.builder.CorrelatorBuilderManager;\n"
                    + "import com.bluesmoke.farm.model.tickdata.Tick;\n"
                    + "import com.bluesmoke.farm.service.feed.FeedService;\n"
                    + "import com.bluesmoke.farm.enumeration.PairResolution;\n"
                    + "import com.bluesmoke.farm.enumeration.Pair;\n"
                    + "\n"
                    + "import java.util.HashMap;\n"
                    + "import java.util.TreeMap;\n"
                    + "import java.util.Random;\n"
                    + "\n"
                    + "public class MovingAverageCorrelator extends GenericCorrelator{\n"
                    + "\n"
                    + "    private int refresh = 0;\n"
                    + "    private double ma;\n"
                    + "    private double sum = 0;\n"
                    + "    private Pair statePair;"
                    + "    private double statePairResolution;"
                    + "\n"
                    + "    public MovingAverageCorrelator(String id, CorrelatorBuilderManager correlatorBuilderManager, CorrelatorPool pool, FeedService feed, GenericCorrelator aggressiveParent, GenericCorrelator passiveParent, HashMap<String, Object> config)\n"
                    + "    {\n"
                    + "        super(\"MovingAverage_\" + pool.getNextID(), correlatorBuilderManager, pool, feed, aggressiveParent, passiveParent, config);\n"
                    + "        Random rand = new Random();\n"
                    + "        this.config.put(\"price_type\", rand.nextInt(4));\n"
                    + "        TreeMap<Double, Pair> randMap = new TreeMap<Double, Pair>();\n"
                    + "        for(Pair pair : Pair.values())\n"
                    + "        {\n"
                    + "            randMap.put(Math.random(), pair);\n"
                    + "        }\n"
                    + "\n"
                    + "        statePair = randMap.firstEntry().getValue();"
                    + "        this.config.put(\"statePair\", statePair);\n"
                    + "        statePairResolution = PairResolution.getResolution(statePair);\n"
                    + "        this.config.put(\"statePairResolution\", statePairResolution);"
                    + "    }\n"
                    + "\n"
                    + "\n"
                    + "    @Override\n"
                    + "    public void createMutant() {\n"
                    + "        new MovingAverageCorrelator(\"MovingAverage_\" + pool.getNextID(), correlatorBuilderManager, pool, feed, null, null, config);\n"
                    + "    }\n"
                    + "\n"
                    + "    @Override\n"
                    + "    public String createState() {\n"
                    + "\n"
                    + "        if(refresh == 0)\n"
                    + "        {\n"
                    + "            refresh = 1000;\n"
                    + "            sum = 0;\n"
                    + "            boolean passedFirst = false;\n"
                    + "            for(Tick tick : ticks)\n"
                    + "            {\n"
                    + "                   double price = 0;\n"
                    + "                   switch ((Integer)config.get(\"price_type\"))\n"
                    + "                   {\n"
                    + "                       case 0:\n"
                    + "                           price = tick.getPairData(statePair.name()).getOpen();\n"
                    + "                           break;\n"
                    + "                       case 1:\n"
                    + "                           price = tick.getPairData(statePair.name()).getClose();\n"
                    + "                           break;\n"
                    + "                       case 2:\n"
                    + "                           price = tick.getPairData(statePair.name()).getHigh();\n"
                    + "                           break;\n"
                    + "                       case 3:\n"
                    + "                           price = tick.getPairData(statePair.name()).getLow();\n"
                    + "                           break;\n"
                    + "                   }"
                    + "                if(passedFirst)\n"
                    + "                {\n"
                    + "                    sum += price;\n"
                    + "                }\n"
                    + "                else {\n"
                    + "                    passedFirst = true;\n"
                    + "                }\n"
                    + "            }\n"
                    + "            ma = sum/(ticks.size() - 1);\n"
                    + "        }\n"
                    + "        else {\n"
                    + "           double priceRemove = 0;"
                    + "           double priceAdd = 0;"
                    + "           switch ((Integer)config.get(\"price_type\"))\n"
                    + "                   {\n"
                    + "                       case 0:\n"
                    + "                           priceRemove = ticks.get(0).getPairData(statePair.name()).getOpen();\n"
                    + "                           priceAdd = currentTick.getPairData(statePair.name()).getOpen();\n"
                    + "                           break;\n"
                    + "                       case 1:\n"
                    + "                           priceRemove = ticks.get(0).getPairData(statePair.name()).getClose();\n"
                    + "                           priceAdd = currentTick.getPairData(statePair.name()).getClose();\n"
                    + "                           break;\n"
                    + "                       case 2:\n"
                    + "                           priceRemove = ticks.get(0).getPairData(statePair.name()).getHigh();\n"
                    + "                           priceAdd = currentTick.getPairData(statePair.name()).getHigh();\n"
                    + "                           break;\n"
                    + "                       case 3:\n"
                    + "                           priceRemove = ticks.get(0).getPairData(statePair.name()).getLow();\n"
                    + "                           priceAdd = currentTick.getPairData(statePair.name()).getLow();\n"
                    + "                           break;\n"
                    + "                   }"
                    + "            sum -= priceRemove;\n"
                    + "            sum += priceAdd;\n"
                    + "            ma = sum/(ticks.size() - 1);\n"
                    + "        }\n"
                    + "        currentUnderlyingComponents.put(\"MA\", ma);\n"
                    + "        refresh--;\n"
                    + "        return \"\" + (int)(ma/(100 * statePairResolution));\n"
                    + "    }\n"
                    + "}\n",
                correlatorBuilderManager,
                feed,
                correlatorPool,
                null,
                null,
                null);

            CorrelatorFromCodeFactory.createCorrelator(
                (String) helper.getBean("classPath"),
                "PriceCorrelator",
                "import com.bluesmoke.farm.correlator.CorrelatorPool;\n"
                    + "import com.bluesmoke.farm.correlator.GenericCorrelator;\n"
                    + "import com.bluesmoke.farm.correlator.builder.CorrelatorBuilderManager;\n"
                    + "import com.bluesmoke.farm.model.tickdata.Tick;\n"
                    + "import com.bluesmoke.farm.service.feed.FeedService;\n"
                    + "import com.bluesmoke.farm.enumeration.PairResolution;\n"
                    + "import com.bluesmoke.farm.enumeration.Pair;\n"
                    + "\n"
                    + "import java.util.HashMap;\n"
                    + "import java.util.TreeMap;\n"
                    + "import java.util.Random;\n"
                    + "\n"
                    + "public class PriceCorrelator extends GenericCorrelator{\n"
                    + "\n"
                    + "    private Pair statePair;"
                    + "    private double statePairResolution;"
                    + "    public PriceCorrelator(String id, CorrelatorBuilderManager correlatorBuilderManager, CorrelatorPool pool, FeedService feed, GenericCorrelator aggressiveParent, GenericCorrelator passiveParent, HashMap<String, Object> config)\n"
                    + "    {\n"
                    + "        super(\"Price_\" + pool.getNextID(), correlatorBuilderManager, pool, feed, aggressiveParent, passiveParent, config);\n"
                    + "        Random rand = new Random();\n"
                    + "        this.config.put(\"price_type\", rand.nextInt(4));\n"
                    + "        "
                    + "        TreeMap<Double, Pair> randMap = new TreeMap<Double, Pair>();\n"
                    + "        for(Pair pair : Pair.values())\n"
                    + "        {\n"
                    + "            randMap.put(Math.random(), pair);\n"
                    + "        }\n"
                    + "\n"
                    + "        statePair = randMap.firstEntry().getValue();"
                    + "        this.config.put(\"statePair\", statePair);\n"
                    + "        statePairResolution = PairResolution.getResolution(statePair);\n"
                    + "        this.config.put(\"statePairResolution\", statePairResolution);"
                    + "    }\n"
                    + "\n"
                    + "\n"
                    + "    @Override\n"
                    + "    public void createMutant() {\n"
                    + "        new PriceCorrelator(\"Price_\" + pool.getNextID(), correlatorBuilderManager, pool, feed, null, null, config);\n"
                    + "    }\n"
                    + "\n"
                    + "    @Override\n"
                    + "    public String createState() {\n"
                    + "\n"
                    + "        double price = 0;\n"
                    + "        switch ((Integer)config.get(\"price_type\"))\n"
                    + "        {\n"
                    + "            case 0:\n"
                    + "                price = currentTick.getPairData(statePair.name()).getOpen();\n"
                    + "                break;\n"
                    + "            case 1:\n"
                    + "                price = currentTick.getPairData(statePair.name()).getClose();\n"
                    + "                break;\n"
                    + "            case 2:\n"
                    + "                price = currentTick.getPairData(statePair.name()).getHigh();\n"
                    + "                break;\n"
                    + "            case 3:\n"
                    + "                price = currentTick.getPairData(statePair.name()).getLow();\n"
                    + "                break;\n"
                    + "        }\n"
                    + "        currentUnderlyingComponents.put(\"price\", price);\n"
                    + "        return \"\" + (int)(price/(10 * statePairResolution));\n"
                    + "    }\n"
                    + "}\n",
                correlatorBuilderManager,
                feed,
                correlatorPool,
                null,
                null,
                null);
          }
        });

    final Button checkPool = new Button("Check Pool");

    feedControl.addComponent(checkPool);

    checkPool.addListener(
        new Button.ClickListener() {
          public void buttonClick(Button.ClickEvent event) {
            System.out.println(correlatorPool.getHandlesInfo());
          }
        });
  }