Ejemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  public Composite createControls(Composite parent, FormToolkit toolkit) {
    Section section = toolkit.createSection(parent, Section.TITLE_BAR);
    section.setText("Time Range");
    section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    mainComposite = toolkit.createComposite(section);
    mainComposite.setLayout(new GridLayout(1, false));
    section.setClient(mainComposite);

    Composite linksComposite = toolkit.createComposite(mainComposite);
    linksComposite.setLayout(new GridLayout(14, false));
    linksComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    toolkit.createLabel(linksComposite, "Last: ");
    createTimeHyperlink(linksComposite, toolkit, "15 minutes", 15 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "1 hour", 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "6 hours", 6 * 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "12 hours", 12 * 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "1 day", 24 * 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "7 days", 7 * 24 * 60 * 60 * 1000L);
    toolkit.createLabel(linksComposite, " | ");
    createTimeHyperlink(linksComposite, toolkit, "30 days", 30 * 24 * 60 * 60 * 1000L);

    Composite timeComposite = toolkit.createComposite(mainComposite);
    timeComposite.setLayout(new GridLayout(4, false));
    timeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    Date toDate = new Date();
    Date fromDate = new Date(toDate.getTime() - PreferenceId.TimeLine.TIMELINE_DEFAULT);

    toolkit.createLabel(timeComposite, "From: ");
    fromDateTime = new CDateTime(timeComposite, CDT.BORDER | CDT.DROP_DOWN);
    fromDateTime.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    fromDateTime.setFormat(CDT.DATE_SHORT | CDT.TIME_SHORT);
    fromDateTime.setSelection(fromDate);

    toolkit.createLabel(timeComposite, "To: ");
    toDateTime = new CDateTime(timeComposite, CDT.BORDER | CDT.DROP_DOWN);
    toDateTime.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    toDateTime.setFormat(CDT.DATE_SHORT | CDT.TIME_SHORT);
    toDateTime.setSelection(toDate);

    SelectionListener selectionListener =
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            getPreferencePanel().update();
          }
        };
    fromDateTime.addSelectionListener(selectionListener);
    toDateTime.addSelectionListener(selectionListener);

    getPreferencePanel().registerCallback(this);

    return mainComposite;
  }