private void loadArticlesUsedOnSelectedDay() {
    String date =
        dtDate.getYear()
            + String.format("%02d", dtDate.getMonth() + 1)
            + String.format("%02d", dtDate.getDay());

    Query<Konsultation> qbe = new Query<Konsultation>(Konsultation.class);
    qbe.add(Konsultation.FLD_DATE, Query.EQUALS, date);
    List<Konsultation> cons = qbe.execute();

    StringBuilder sb = new StringBuilder();

    for (Konsultation c : cons) {
      List<Verrechnet> leistungen = c.getLeistungen();
      for (Verrechnet v : leistungen) {
        IVerrechenbar vv = v.getVerrechenbar();
        if (vv instanceof Artikel) {
          Artikel art = (Artikel) vv;
          Mandant mandator = ElexisEventDispatcher.getSelectedMandator();
          IStockEntry stockEntry =
              CoreHub.getStockService()
                  .findPreferredStockEntryForArticle(
                      art.storeToString(), (mandator != null) ? mandator.getId() : null);
          if (stockEntry != null) {
            StockEntry se = (StockEntry) stockEntry;
            currOrder.addBestellungEntry(
                se.getArticle(), se.getStock(), se.getProvider(), v.getZahl());
          } else {
            sb.append(art.getLabel() + " ist kein Lagerartikel.\n");
          }
        }
      }
    }
  }
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());

    DateTime calendar = new DateTime(shell, SWT.CALENDAR);
    calendar.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            System.out.println("calendar date changed");
          }
        });

    DateTime time = new DateTime(shell, SWT.TIME);
    time.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            System.out.println("time changed");
          }
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  private void setSqlToDate(DateTime dateTo) {

    Calendar cal = GregorianCalendar.getInstance();
    cal.set(Calendar.YEAR, dateTo.getYear());
    cal.set(Calendar.MONTH, dateTo.getMonth());
    cal.set(Calendar.DAY_OF_MONTH, dateTo.getDay());

    TO_DATE = cal;
  }
  private void setSqlFromDate(DateTime dateFrom) {

    Calendar cal = GregorianCalendar.getInstance();
    cal.set(Calendar.YEAR, dateFrom.getYear());
    cal.set(Calendar.MONTH, dateFrom.getMonth());
    cal.set(Calendar.DAY_OF_MONTH, dateFrom.getDay());

    FROM_DATE = cal;
  }
 @Override
 protected void doStore() {
   String value;
   if (mOptional && !mEnableButton.getSelection()) {
     value = ""; // $NON-NLS-1$
   } else {
     TimeOfDay time =
         TimeOfDay.create(mTime.getHours(), mTime.getMinutes(), mTime.getSeconds(), mTimeZone);
     value = time.toFormattedString();
   }
   getPreferenceStore().setValue(getPreferenceName(), value);
 }
  public MainMenuComposite(Composite parent, int style) {
    super(parent, style);
    DateTime calendar = new DateTime(this, SWT.CALENDAR);
    calendar.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            System.out.println("calendar date changed");
          }
        });
    calendar.setBounds(10, 10, 300, 300);
    calendar.pack();

    // TODO Auto-generated constructor stub
  }
  private void initDateCalendar(Composite parent) {
    dateCalendar = new DateTime(parent, SWT.BORDER | SWT.DROP_DOWN);
    dateCalendar.setToolTipText("Calendar");
    dateCalendar.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            calendarValue.set(Calendar.YEAR, dateCalendar.getYear());
            calendarValue.set(Calendar.MONTH, dateCalendar.getMonth());
            calendarValue.set(Calendar.DAY_OF_MONTH, dateCalendar.getDay());
          }
        });
  }
  private void initDateTime(Composite parent) {
    dateTime = new DateTime(parent, SWT.BORDER | SWT.TIME);
    dateTime.setToolTipText("Time");
    dateTime.addSelectionListener(
        new SelectionAdapter() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            calendarValue.set(Calendar.HOUR_OF_DAY, dateTime.getHours());
            calendarValue.set(Calendar.MINUTE, dateTime.getMinutes());
            calendarValue.set(Calendar.SECOND, dateTime.getSeconds());
          }
        });
  }
 @Override
 protected void doFillIntoGrid(Composite parent, int numColumns) {
   getLabelControl(parent);
   mTime = new DateTime(parent, SWT.TIME | SWT.LONG);
   mTime.setTime(0, 0, 0);
   GridDataFactory.defaultsFor(mTime).applyTo(mTime);
 }
Beispiel #10
0
  @PostConstruct
  public void postConstruct(Composite parent, ITodoService iTodoService) {
    GridLayout gridLayout = new GridLayout(2, false);
    parent.setLayout(gridLayout);

    Label lblSummary = new Label(parent, SWT.NONE);
    lblSummary.setText("Summary");

    txtSummary = new Text(parent, SWT.BORDER);
    txtSummary.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    Label lblDescription = new Label(parent, SWT.NONE);
    lblDescription.setText("Description");

    txtDescription = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    txtDescription.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Label lblDueDate = new Label(parent, SWT.NONE);
    lblDueDate.setText("Due Date");

    dateTime = new DateTime(parent, SWT.BORDER);
    dateTime.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

    Label lblDone = new Label(parent, SWT.NONE);
    lblDone.setText("Done");

    Button btnDone = new Button(parent, SWT.CHECK);
    btnDone.setText("Done");

    //		updateUI(todo);
  }
  protected void addDirtyMarker(DateTime dateTime) {

    if (dateTime != null) {
      dateTime.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              markDirty();
            }
          });
    }
  }
 private void load(String string) {
   if (StringUtils.isNotBlank(string)) {
     TimeOfDay time = TimeOfDay.create(string);
     if (time != null) {
       mTime.setTime(
           time.getHour(mTimeZone), time.getMinute(mTimeZone), time.getSecond(mTimeZone));
       if (mOptional) {
         mEnableButton.setSelection(true);
         mEnablement.restore();
       }
     }
   }
 }
 public void fire(Object event) {
   FlatPopupMenu dlg = new FlatPopupMenu(button, null, true, false, false, false);
   DateTime ctrl = new DateTime(dlg.getControl(), SWT.CALENDAR | SWT.LONG);
   long date = DateTimeUtil.getDateFromString(text.getText());
   if (date != 0) {
     Calendar c = Calendar.getInstance();
     c.setTimeInMillis(date);
     ctrl.setYear(c.get(Calendar.YEAR));
     ctrl.setMonth(c.get(Calendar.MONTH));
     ctrl.setDay(c.get(Calendar.DAY_OF_MONTH));
   }
   ctrl.addSelectionListener(
       new SelectionListenerWithData<DateTime>(ctrl) {
         public void widgetSelected(SelectionEvent e) {
           Calendar c = Calendar.getInstance();
           c.set(Calendar.YEAR, data().getYear());
           c.set(Calendar.MONTH, data().getMonth());
           c.set(Calendar.DAY_OF_MONTH, data().getDay());
           text.setText(DateTimeUtil.getDateString(c.getTimeInMillis()));
         }
       });
   dlg.show(button, FlatPopupMenu.Orientation.BOTTOM, true);
 }
  @Override
  protected Control createDialogArea(Composite parent) {
    Composite area = new Composite(parent, SWT.NONE);
    area.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    area.setLayout(new GridLayout(1, false));

    Composite dateComposite = new Composite(area, SWT.NONE);
    dateComposite.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    dateComposite.setLayout(new GridLayout(1, false));
    dtDate = new DateTime(area, SWT.DATE | SWT.DROP_DOWN);
    dtDate.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            loadArticlesUsedOnSelectedDay();
            tableViewer.setInput(currOrder.getEntries());
          }
        });

    Composite tableComposite = new Composite(area, SWT.NONE);
    tableComposite.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    TableColumnLayout tcLayout = new TableColumnLayout();
    tableComposite.setLayout(tcLayout);

    tableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION);
    Table table = tableViewer.getTable();
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    TableViewerColumn tvc = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tcAmount = tvc.getColumn();
    tcLayout.setColumnData(tcAmount, new ColumnPixelData(70, false, false));
    tcAmount.setText(Messages.DailyOrderDialog_Amount);

    tvc = new TableViewerColumn(tableViewer, SWT.NONE);
    TableColumn tcArticle = tvc.getColumn();
    tcLayout.setColumnData(tcArticle, new ColumnPixelData(300, true, true));
    tcArticle.setText(Messages.DailyOrderDialog_Article);

    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.setLabelProvider(new OrderLabelProvider());

    loadArticlesUsedOnSelectedDay();
    tableViewer.setInput(currOrder.getEntries());

    return area;
  }
Beispiel #15
0
  private void generate() {
    Calendar calendar = Calendar.getInstance();
    calendar.set(dtFrom.getYear(), dtFrom.getMonth(), dtFrom.getDay());
    Date dateFrom = calendar.getTime();
    calendar.set(dtTo.getYear(), dtTo.getMonth(), dtTo.getDay());
    Date dateTo = calendar.getTime();
    setData = new SetData(new Date(), textComment.getText(), dateFrom, dateTo);
    tableSet.setValues(setData);

    final int octet = spinnerOctet.getSelection();
    final String octetValue = textOctet.getText();
    final int keys = spinnerCount.getSelection();
    try {
      new ProgressMonitorDialog(getShell())
          .run(
              true,
              true,
              new IRunnableWithProgress() {
                @Override
                public void run(IProgressMonitor monitor)
                    throws InvocationTargetException, InterruptedException {
                  monitor.beginTask("Генерация ключей…", keys);
                  for (int i = 0; i < keys; ++i) {
                    String key;
                    do {
                      if (monitor.isCanceled()) {
                        throw new InterruptedException();
                      }
                      key = KeyGenerator.generateKey(octetValue, octet);
                    } while (setData.isKeyExists(key));
                    setData.addKey(key, true);
                    monitor.worked(1);
                  }
                }
              });
    } catch (InvocationTargetException e) {
      throw new KeyException("Ошибка при генерации ключей", e.getCause());
    } catch (InterruptedException e) {
    }
    tableKey.setValues(setData.getKeys());
  }
 /**
  * 获得终止时间
  *
  * @return
  */
 public Date getEndDateTime() {
   Calendar calendar = Calendar.getInstance();
   calendar.set(endDate.getYear(), endDate.getMonth(), endDate.getDay(), 23, 59, 59);
   return calendar.getTime();
 }
Beispiel #17
0
  private void ViewDataTab() {

    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    GridLayout gl_composite = new GridLayout(1, false);
    gl_composite.verticalSpacing = 0;
    gl_composite.marginWidth = 0;
    gl_composite.horizontalSpacing = 0;
    composite.setLayout(gl_composite);

    Group grpFilters = new Group(composite, SWT.NONE);
    grpFilters.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    grpFilters.setText("Filtri");
    grpFilters.setLayout(new GridLayout(4, false));

    Label lblComp = new Label(grpFilters, SWT.NONE);
    lblComp.setText("Compartimento");

    Label lblEdificio = new Label(grpFilters, SWT.NONE);
    lblEdificio.setText("Edificio");

    Label lblDa = new Label(grpFilters, SWT.NONE);
    lblDa.setText("Data:");
    new Label(grpFilters, SWT.NONE);

    comboComp = new Combo(grpFilters, SWT.READ_ONLY);
    comboComp.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (comboComp.getText().equals("*")) {
              comboEdif.setItems(DataView.EdifItems());
            } else {
              comboEdif.setItems(DataView.EdifItems(comboComp.getText()));
            }
          }
        });
    GridData gd_comboComp = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_comboComp.widthHint = 150;
    comboComp.setLayoutData(gd_comboComp);
    comboComp.setItems(compItems);
    comboComp.add("*");

    comboEdif = new Combo(grpFilters, SWT.READ_ONLY);
    GridData gd_comboEdif = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_comboEdif.widthHint = 150;
    comboEdif.setLayoutData(gd_comboEdif);

    dateTime = new DateTime(grpFilters, SWT.BORDER);
    dateTime.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1));
    dateTime.setDate(2014, 0, 1);

    Button btnGo = new Button(grpFilters, SWT.NONE);
    btnGo.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            year = dateTime.getYear();
            month = dateTime.getMonth();
            date = dateTime.getDay();
            edificio = new Edificio();
            edificio.setIdEdificio(
                Integer.parseInt(
                    comboEdif.getText().substring(0, comboEdif.getText().indexOf(":"))));

            buttonGoActions();
          }
        });

    GridData gd_btnGo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_btnGo.widthHint = 70;
    btnGo.setLayoutData(gd_btnGo);
    btnGo.setText("GO");

    tabResults = new TabFolder(composite, SWT.NONE);
    tabResults.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    tabMeterAcqua();

    tabMeterRipartitoreCalore();

    tabMeterSonde();

    TabItem tbtmMeterTermie = new TabItem(tabResults, SWT.NONE);
    tbtmMeterTermie.setText("Meter Termie");

    TabItem tbtmMeterElettrico = new TabItem(tabResults, SWT.NONE);
    tbtmMeterElettrico.setText("Meter Elettrico");

    TabItem tbtmMeterGas = new TabItem(tabResults, SWT.NONE);
    tbtmMeterGas.setText("Meter Gas");
  }
 /**
  * 获得起始时间
  *
  * @return
  */
 public Date getStartDateTime() {
   Calendar calendar = Calendar.getInstance();
   calendar.set(startDate.getYear(), startDate.getMonth(), startDate.getDay(), 0, 0, 0);
   return calendar.getTime();
 }
Beispiel #19
0
  public void show(long stime, long etime) {
    final Shell dialog = new Shell(display, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    dialog.setLayout(new GridLayout(4, false));
    dialog.setText("Time Range");
    UIUtil.setDialogDefaultFunctions(dialog);

    Label label = new Label(dialog, SWT.NONE);
    label.setText("From");
    final DateTime startTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    startTime.setHours(DateUtil.getHour(stime));
    startTime.setMinutes(DateUtil.getMin(stime));

    label = new Label(dialog, SWT.NONE);
    label.setText("To");
    final DateTime endTime = new DateTime(dialog, SWT.TIME | SWT.SHORT);
    endTime.setHours(DateUtil.getHour(etime));
    endTime.setMinutes(DateUtil.getMin(etime));

    Button okButton = new Button(dialog, SWT.PUSH);
    okButton.setText("&OK");
    okButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    okButton.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                try {
                  String fromTime =
                      yyyymmdd
                          + (startTime.getHours() < 10 ? "0" : "")
                          + startTime.getHours()
                          + (startTime.getMinutes() < 10 ? "0" : "")
                          + startTime.getMinutes();
                  String toTime =
                      yyyymmdd
                          + (endTime.getHours() < 10 ? "0" : "")
                          + endTime.getHours()
                          + (endTime.getMinutes() < 10 ? "0" : "")
                          + endTime.getMinutes();
                  long stime = DateUtil.getTime(fromTime, "yyyyMMddHHmm");
                  long etime = DateUtil.getTime(toTime, "yyyyMMddHHmm");
                  if (etime <= stime) {
                    MessageDialog.openWarning(
                        dialog,
                        "Warning",
                        "Time range is incorrect. "
                            + DateUtil.timestamp(stime)
                            + " ~ "
                            + DateUtil.timestamp(etime));
                  } else {
                    callback.setTimeRange(stime, etime);
                    dialog.close();
                  }
                } catch (Exception e) {
                  e.printStackTrace();
                  MessageDialog.openError(dialog, "Error", "Date format error:" + e.getMessage());
                }
                break;
            }
          }
        });

    Button cancelButton = new Button(dialog, SWT.PUSH);
    cancelButton.setText("&Cancel");
    cancelButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 2, 1));
    cancelButton.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.Selection:
                dialog.close();
                break;
            }
          }
        });

    dialog.setDefaultButton(okButton);
    dialog.pack();
    dialog.open();
  }
Beispiel #20
0
  @Override
  public void createControl(Composite parent) {
    container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);

    layout.numColumns = 2;
    Label label1 = new Label(container, SWT.NULL);
    label1.setText("Select Your Agent");
    listViewer = new ListViewer(container);
    list.add("Big Travels");
    list.add("Aviator Travels");
    list.add("BTM Travels");
    list.add("Arihanth Travels");
    list.add("Atlas Travels");
    Object[] list1 = list.toArray();
    listViewer.add(list1);

    Label label2 = new Label(container, SWT.NULL);
    label2.setText("Select travel start date:");
    dateFrom = new DateTime(container, SWT.BORDER | SWT.DATE | SWT.DROP_DOWN);
    listViewer.addSelectionChangedListener(
        new ISelectionChangedListener() {
          public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            sb = "";
            // sb.append("tatal " + selection.size() + " items selected: ");
            for (java.util.Iterator iterator = selection.iterator(); iterator.hasNext(); ) {
              sb = (String) (iterator.next());
              // sb.replace(0,sb.length(),(String) iterator.next());
              break;
            }

            System.out.println("Your agent is " + sb);
          }
        });
    dateFrom.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {

            // System.out.println ("Calendar date selected (MM/DD/YYYY) = " + (dateFrom.getMonth ()
            // + 1) + "/" + dateFrom.getDay () + "/" + dateFrom.getYear ());
            date.delete(0, date.length());
            date.append((dateFrom.getMonth() + 1));
            date.append("/");
            date.append(dateFrom.getDay());
            date.append("/");
            date.append(dateFrom.getYear());
            // System.out.println("After adding to date "+date);
            // System.out.println ("Date selected (MM/YYYY) = " + (date.getMonth () + 1) + "/" +
            // date.getYear ());

            // System.out.println ("Time selected (HH:MM) = " + time.getHours () + ":" +
            // (time.getMinutes () < 10 ? "0" : "") + time.getMinutes ());

            // dialog.close ();

          }
        });

    // dateFrom.setDate();
    /*L bel label1 = new Label(container, SWT.NULL);
    label1.setText("Travel Name");

    text1 = new Text(container, SWT.BORDER | SWT.SINGLE);
    text1.setText("");
    text1.addKeyListener(new KeyListener() {

      @Override
      public void keyPressed(KeyEvent e) {
      }

      @Override
      public void keyReleased(KeyEvent e) {
        if (!text1.getText().isEmpty()) {
          setPageComplete(true);

        }
      }

    });*/
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    // listViewer.setLayoutData(gd);
    // Required to avoid an error in the system
    setControl(container);
    setPageComplete(false);
  }
  /** @see IDialogPage#createControl(Composite) */
  @Override
  public void createControl(Composite parent) {

    // Set up the composite to hold all the information
    sc = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
    sc.setLayout(new FillLayout());

    final Composite composite = new Composite(sc, SWT.NULL);
    composite.setLocation(-708, 1);
    composite.setLayout(new GridLayout(2, false));

    // Specify the expansion Adapter
    expansionAdapter =
        new ExpansionAdapter() {
          @Override
          public void expansionStateChanged(ExpansionEvent e) {
            // advanced options expanded, resize
            composite.layout();
            sc.notifyListeners(SWT.Resize, null);

            // force shell resize
            Point size;
            if (e.getState()) size = getShell().computeSize(550, 920);
            else size = getShell().computeSize(550, 400);

            getShell().setSize(size);
          }
        };

    Label lblNewLabel = new Label(composite, SWT.NONE);
    lblNewLabel.setText("&ICAT site ID");

    icatIDCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
    GridData gd_icatIDCombo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_icatIDCombo.widthHint = 269;
    icatIDCombo.setLayoutData(gd_icatIDCombo);
    icatIDCombo.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            logger.debug("selection changed: " + icatIDCombo.getText());

            // change remaining parameters
            int index = icatIDCombo.getSelectionIndex();
            icatSiteNameText.setText(
                getToken(index, preferenceStore.getString("ICAT_NAME_PREF"), DELIMITER));
            txtSftpServer.setText(
                getToken(index, preferenceStore.getString("ICAT_SFTPSERVER_PREF"), DELIMITER));
            txtDirectory.setText(
                getToken(index, preferenceStore.getString("ICAT_DOWNLOADDIR_PREF"), DELIMITER));
          }
        });

    /*
     * populate wizard with current ICAT preferences
     */
    icatIDCombo.removeAll();

    String[] tokens = preferenceStore.getDefaultString("ICAT_ID_PREF").split(DELIMITER);

    for (int count = 0; count < tokens.length; count++) {
      icatIDCombo.add(tokens[count]);
    }
    icatIDCombo.select(0);

    int index = icatIDCombo.getSelectionIndex();

    Label lblicatDatabase = new Label(composite, SWT.NONE);
    lblicatDatabase.setText("&ICAT site name:");

    icatSiteNameText = new Text(composite, SWT.BORDER | SWT.READ_ONLY);
    GridData gd_icatSiteNameText = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_icatSiteNameText.widthHint = 260;
    icatSiteNameText.setLayoutData(gd_icatSiteNameText);
    icatSiteNameText.setEditable(false);
    icatSiteNameText.setText(
        getToken(index, preferenceStore.getString("ICAT_NAME_PREF"), DELIMITER));
    icatSiteNameText.setBounds(113, 53, 212, 27);

    Label fedidLbl = new Label(composite, SWT.NONE);
    fedidLbl.setText("&FedId:");

    txtFedid = new Text(composite, SWT.BORDER);
    GridData gd_txtFedid = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_txtFedid.widthHint = 260;
    txtFedid.setLayoutData(gd_txtFedid);
    txtFedid.setText(initFedid);
    txtFedid.addKeyListener(this);

    Label passwordLbl = new Label(composite, SWT.NONE);
    passwordLbl.setBounds(4, 139, 64, 13);
    passwordLbl.setText("&Password:"******"&Project name:");
    txtProject = new Text(composite, SWT.BORDER);
    GridData gd_txtProject = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_txtProject.widthHint = 260;
    txtProject.setLayoutData(gd_txtProject);
    txtProject.setBounds(113, 173, 212, 27);
    txtProject.setText(initProject);
    txtProject.addKeyListener(this);
    sc.setContent(composite);
    sc.setExpandVertical(true);
    sc.setExpandHorizontal(true);

    new Label(composite, SWT.NONE);
    new Label(composite, SWT.NONE);

    /** set-up advanced options GUI elements */
    advancedOptionsExpander = new ExpandableComposite(composite, SWT.NONE);
    GridData gd_advancedOptionsExpander = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
    gd_advancedOptionsExpander.widthHint = 242;
    advancedOptionsExpander.setLayoutData(gd_advancedOptionsExpander);
    advancedOptionsExpander.setLayout(new GridLayout(2, false));
    advancedOptionsExpander.setText("Advanced Options");
    advancedOptionsExpander.setExpanded(false);

    Composite optionsComposite = new Composite(advancedOptionsExpander, SWT.NONE);
    optionsComposite.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    optionsComposite.setLayout(new GridLayout(3, false));

    Label sftpServerLbl = new Label(optionsComposite, SWT.NONE);
    sftpServerLbl.setText("&SFTP server:");

    txtSftpServer = new Text(optionsComposite, SWT.BORDER);
    GridData gd_txtSftpServer = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_txtSftpServer.widthHint = 193;
    txtSftpServer.setLayoutData(gd_txtSftpServer);
    txtSftpServer.setEditable(true);
    txtSftpServer.setText(
        getToken(index, preferenceStore.getString("ICAT_SFTPSERVER_PREF"), DELIMITER));

    final Button btnSftpTest = new Button(optionsComposite, SWT.NONE);
    GridData gd_btnSftpTest = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_btnSftpTest.widthHint = 100;
    btnSftpTest.setLayoutData(gd_btnSftpTest);
    btnSftpTest.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            /*
             * test server using ping
             */
            if (NetworkUtils.isReachable(txtSftpServer.getText())) {
              Image okImage = (ResourceManager.getPluginImage(ICAT_PLUGIN_ID, "icons/ok.png"));
              ;
              btnSftpTest.setImage(okImage);
            } else {
              Image noImage = (ResourceManager.getPluginImage(ICAT_PLUGIN_ID, "icons/no.png"));
              ;
              btnSftpTest.setImage(noImage);
            }
          }
        });
    btnSftpTest.setText("Test");

    txtSftpServer.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            btnSftpTest.setImage(null);
          }
        });

    Label lbldownloadDirectory = new Label(optionsComposite, SWT.NULL);
    lbldownloadDirectory.setText("&Download directory:");

    txtDirectory = new Text(optionsComposite, SWT.BORDER);
    GridData gd_txtDirectory = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_txtDirectory.widthHint = 193;
    txtDirectory.setLayoutData(gd_txtDirectory);
    txtDirectory.setEditable(true);
    txtDirectory.setEnabled(true);

    txtDirectory.setText(
        getToken(index, preferenceStore.getString("ICAT_DOWNLOADDIR_PREF"), DELIMITER));

    Button BtnBrowseDirectory = new Button(optionsComposite, SWT.PUSH);
    GridData gd_BtnBrowseDirectory = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_BtnBrowseDirectory.widthHint = 100;
    BtnBrowseDirectory.setLayoutData(gd_BtnBrowseDirectory);
    BtnBrowseDirectory.setText("Browse...");
    BtnBrowseDirectory.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleDownloadDirBrowse();
          }
        });

    Label lbltruststorePath = new Label(optionsComposite, SWT.NONE);
    lbltruststorePath.setBounds(10, 131, 103, 19);
    lbltruststorePath.setText("&Truststore path:");

    txtTruststore = new Text(optionsComposite, SWT.BORDER);
    txtTruststore.setText(
        getToken(index, preferenceStore.getString("ICAT_TRUSTSTORE_PATH_PREF"), DELIMITER));
    GridData gd_txtTruststore = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_txtTruststore.widthHint = 193;
    txtTruststore.setLayoutData(gd_txtTruststore);
    txtTruststore.setEnabled(true);
    txtTruststore.setEditable(true);

    Button BtnBrowseTruststore = new Button(optionsComposite, SWT.PUSH);
    GridData gd_BtnBrowseTruststore = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_BtnBrowseTruststore.widthHint = 100;
    BtnBrowseTruststore.setLayoutData(gd_BtnBrowseTruststore);
    BtnBrowseTruststore.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleTruststoreBrowse();
          }
        });
    BtnBrowseTruststore.setText("Browse...");

    Label lbltruststorePassword = new Label(optionsComposite, SWT.NONE);
    lbltruststorePassword.setText("&Truststore password:"******"ICAT_TRUSTSTORE_PASS_PREF"), DELIMITER));
    GridData gd_txtTruststorePassword = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gd_txtTruststorePassword.widthHint = 193;
    txtTruststorePassword.setLayoutData(gd_txtTruststorePassword);
    txtTruststorePassword.setEnabled(true);
    txtTruststorePassword.addKeyListener(this);

    final Button btnShowPassword = new Button(optionsComposite, SWT.CHECK);
    btnShowPassword.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (btnShowPassword.getSelection()) {
              txtTruststorePassword.setEchoChar((char) 0);
            } else {
              txtTruststorePassword.setEchoChar('*');
            }
          }
        });
    btnShowPassword.setText("Show password");

    // set default FROM date to current date
    Calendar calA = Calendar.getInstance();

    Label lblFrom = new Label(optionsComposite, SWT.TOP);
    lblFrom.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    lblFrom.setText("Visit StartDate from:");
    dateFrom = new DateTime(optionsComposite, SWT.NONE | SWT.CALENDAR | SWT.DROP_DOWN);
    dateFrom.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_FOREGROUND));
    dateFrom.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
    GridData gd_dateFrom = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
    gd_dateFrom.widthHint = 193;
    dateFrom.setLayoutData(gd_dateFrom);
    dateFrom.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            // set from date
            setSqlFromDate(dateFrom);
          }
        });

    dateFrom.setYear(2006); // calA.get(Calendar.YEAR));
    dateFrom.setMonth(calA.get(Calendar.MONTH));
    dateFrom.setDay(calA.get(Calendar.DAY_OF_YEAR));
    setSqlFromDate(dateFrom);

    Label lblTo = new Label(optionsComposite, SWT.TOP);
    lblTo.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    lblTo.setText("Visit StartDate to:");
    dateTo = new DateTime(optionsComposite, SWT.NONE | SWT.CALENDAR | SWT.DROP_DOWN);
    dateTo.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_BACKGROUND_GRADIENT));
    dateTo.setForeground(SWTResourceManager.getColor(SWT.COLOR_WIDGET_FOREGROUND));
    GridData gd_dateTo = new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1);
    gd_dateTo.widthHint = 193;
    dateTo.setLayoutData(gd_dateTo);
    dateTo.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            // set to date
            setSqlToDate(dateTo);
          }
        });
    // end with current date + 1 month
    dateTo.setYear(calA.get(Calendar.YEAR));
    dateTo.setMonth(calA.get(Calendar.MONTH) + 1);
    dateTo.setDay(calA.get(Calendar.DAY_OF_YEAR));
    setSqlToDate(dateTo);

    advancedOptionsExpander.setClient(optionsComposite);
    new Label(optionsComposite, SWT.NONE);
    new Label(optionsComposite, SWT.NONE);
    new Label(optionsComposite, SWT.NONE);
    advancedOptionsExpander.addExpansionListener(expansionAdapter);
    setControl(composite);

    dialogChanged();

    new Label(composite, SWT.NONE);
    new Label(composite, SWT.NONE);
  }
Beispiel #22
0
  public NewComposite(Composite parent, int style) {
    super(parent, style);

    setLayout(new GridLayout(2, false));

    GridData gd = new GridData(SWT.NONE, SWT.NONE, false, false);

    new Label(this, SWT.NONE).setText("Количество октетов:");
    spinnerOctet = new Spinner(this, SWT.BORDER);
    spinnerOctet.setLayoutData(gd);
    spinnerOctet.setMinimum(2);
    spinnerOctet.setMaximum(8);

    new Label(this, SWT.NONE).setText("Количество ключей:");
    spinnerCount = new Spinner(this, SWT.BORDER);
    spinnerCount.setLayoutData(gd);
    spinnerCount.setMinimum(1);
    spinnerCount.setMaximum(20000);

    new Label(this, SWT.NONE).setText("Настраиваемый октет:");
    textOctet = new Text(this, SWT.BORDER);
    textOctet.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    textOctet.addVerifyListener(
        new VerifyListener() {
          @Override
          public void verifyText(VerifyEvent event) {
            int len = event.text.length();
            if (len > 0) {
              int allowed = CUSTOM_OCTET_LENGTH - ((Text) event.widget).getText().length();
              if (len > allowed) {
                event.text = event.text.substring(0, allowed);
              }
              if (!PATTERN_ALPHANUM.matcher(event.text).matches()) {
                event.doit = false;
              } else {
                event.text = event.text.toUpperCase();
              }
            }
          }
        });

    new Label(this, SWT.NONE).setText("Комментарий:");
    textComment = new Text(this, SWT.BORDER);
    textComment.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

    new Label(this, SWT.NONE).setText("Начало действия ключа:");
    dtFrom = new DateTime(this, SWT.BORDER | SWT.DATE);
    Calendar calendar = Calendar.getInstance();
    dtFrom.setDate(
        calendar.get(Calendar.YEAR),
        calendar.get(Calendar.MONTH),
        calendar.get(Calendar.DAY_OF_MONTH));

    new Label(this, SWT.NONE).setText("Окончание действия ключа:");
    dtTo = new DateTime(this, SWT.BORDER | SWT.DATE);
    calendar.add(Calendar.YEAR, 1);
    dtTo.setDate(
        calendar.get(Calendar.YEAR),
        calendar.get(Calendar.MONTH),
        calendar.get(Calendar.DAY_OF_MONTH));

    Button button = new Button(this, SWT.PUSH);
    button.setImage(new Image(getShell().getDisplay(), getClass().getResourceAsStream("/new.gif")));
    GridData buttonGridData = new GridData(SWT.NONE, SWT.NONE, false, false, 2, 1);
    button.setLayoutData(buttonGridData);
    button.setText("Создать");
    button.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent event) {
            generate();
            buttonSave.setEnabled(true);
          }
        });

    tableSet = new SetTable(this, false);
    tableSet.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));

    tableKey = new KeyTable(this);
    GridData gdKeyTable = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
    gdKeyTable.heightHint = 50;
    tableKey.setLayoutData(gdKeyTable);

    buttonSave = new Button(this, SWT.PUSH);
    buttonSave.setLayoutData(buttonGridData);
    buttonSave.setText("Сохранить");
    buttonSave.setImage(
        new Image(getShell().getDisplay(), getClass().getResourceAsStream("/export.gif")));
    buttonSave.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            save();
            buttonSave.setEnabled(false);
          }
        });
    buttonSave.setEnabled(false);
  }
  private void createSenateInputParameters(Composite client) {
    Section inputParamsSection =
        toolkit.createSection(client, Section.TITLE_BAR | Section.EXPANDED | Section.DESCRIPTION);
    GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(inputParamsSection);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(inputParamsSection);
    inputParamsSection.setText("Input Parameters");

    ScrolledComposite sc = new ScrolledComposite(inputParamsSection, SWT.H_SCROLL | SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(sc);

    Composite sectionClient = toolkit.createComposite(inputParamsSection);
    sc.setContent(sectionClient);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(sc);
    GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(sectionClient);
    inputParamsSection.setClient(sectionClient);

    String[] loading = {"Loading..."};

    Label congressLabel = toolkit.createLabel(sectionClient, "Congress:", SWT.NONE);
    GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(congressLabel);
    cmbCongress = new Combo(sectionClient, SWT.FLAT | SWT.READ_ONLY);
    GridDataFactory.fillDefaults().grab(true, false).span(2, 0).applyTo(cmbCongress);
    toolkit.adapt(cmbCongress);
    cmbCongress.setItems(loading);
    cmbCongress.select(0);

    Label dummy1 = new Label(sectionClient, SWT.NONE);
    dummy1.setText("Senator:");
    GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(dummy1);

    senatorTable = new Table(sectionClient, SWT.BORDER | SWT.MULTI);
    GridDataFactory.fillDefaults().grab(true, true).span(1, 3).hint(90, 50).applyTo(senatorTable);

    Composite buttonComp = new Composite(sectionClient, SWT.NONE);
    GridLayout btnLayout = new GridLayout();
    btnLayout.marginWidth = btnLayout.marginHeight = 0;
    btnLayout.makeColumnsEqualWidth = false;
    buttonComp.setLayout(btnLayout);
    buttonComp.setLayoutData(new GridData(GridData.FILL_VERTICAL));

    addSenatorBtn = new Button(buttonComp, SWT.PUSH); // $NON-NLS-1$
    addSenatorBtn.setText("Add...");
    GridDataFactory.fillDefaults().grab(false, false).span(1, 1).applyTo(addSenatorBtn);

    addSenatorBtn.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            handleAdd(addSenatorBtn.getShell());
          }
        });
    addSenatorBtn.setEnabled(false);

    removeSenatorButton = new Button(buttonComp, SWT.PUSH);
    removeSenatorButton.setText("Remove...");
    GridDataFactory.fillDefaults().grab(false, false).span(1, 1).applyTo(removeSenatorButton);
    removeSenatorButton.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {

            for (TableItem item : senatorTable.getSelection()) {
              selectedSenators.remove(item.getText());
              item.dispose();
            }
            if (selectedSenators.size() == 0) {
              removeSenatorButton.setEnabled(false);
            }
          }
        });
    removeSenatorButton.setEnabled(false);

    TacitFormComposite.createEmptyRow(toolkit, sectionClient);
    Group limitGroup = new Group(client, SWT.SHADOW_IN);
    limitGroup.setText("Limit Records");
    // limitGroup.setBackground(client.getBackground());
    limitGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout limitLayout = new GridLayout();
    limitLayout.numColumns = 1;
    limitGroup.setLayout(limitLayout);

    final Composite limitRecordsClient = new Composite(limitGroup, SWT.None);
    GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(limitRecordsClient);
    GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).applyTo(limitRecordsClient);

    limitRecords = new Button(limitRecordsClient, SWT.CHECK);
    limitRecords.setText("Limit Records per Senator");
    GridDataFactory.fillDefaults().grab(false, false).span(3, 0).applyTo(limitRecords);
    limitRecords.addSelectionListener(
        new SelectionListener() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (!limitRecords.getSelection()) {
              form.getMessageManager().removeMessage("limitText");
            }
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub
          }
        });

    final Label sortLabel = new Label(limitRecordsClient, SWT.NONE);
    sortLabel.setText("Sort Records by Date:");
    GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(sortLabel);
    sortLabel.setEnabled(false);

    sortByDateYes = new Button(limitRecordsClient, SWT.RADIO);
    sortByDateYes.setText("Yes");
    sortByDateYes.setEnabled(false);
    sortByDateYes.setSelection(true);

    sortByDateNo = new Button(limitRecordsClient, SWT.RADIO);
    sortByDateNo.setText("No");
    sortByDateNo.setEnabled(false);

    final Label limitLabel = new Label(limitRecordsClient, SWT.NONE);
    limitLabel.setText("No.of.Records per Senator:");
    GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(limitLabel);
    limitLabel.setEnabled(false);
    limitText = new Text(limitRecordsClient, SWT.BORDER);
    limitText.setText("1");
    GridDataFactory.fillDefaults().grab(true, false).span(2, 0).applyTo(limitText);
    limitText.setEnabled(false);

    limitText.addKeyListener(
        new KeyListener() {
          @Override
          public void keyReleased(KeyEvent e) {
            if (!(e.character >= '0' && e.character <= '9')) {
              form.getMessageManager()
                  .addMessage(
                      "limitText",
                      "Provide valid no.of.records per senator",
                      null,
                      IMessageProvider.ERROR);
              limitText.setText("");
            } else {
              form.getMessageManager().removeMessage("limitText");
            }
          }

          @Override
          public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub
          }
        });

    TacitFormComposite.createEmptyRow(toolkit, client);

    Group dateGroup = new Group(client, SWT.SHADOW_IN);
    dateGroup.setText("Date");
    dateGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    dateGroup.setLayout(layout);

    dateRange = new Button(dateGroup, SWT.CHECK);
    dateRange.setText("Specify Date Range");

    // TacitFormComposite.createEmptyRow(toolkit, group);
    final Composite dateRangeClient = new Composite(dateGroup, SWT.None);
    GridDataFactory.fillDefaults().grab(true, false).span(1, 1).applyTo(dateRangeClient);
    GridLayoutFactory.fillDefaults().numColumns(4).equalWidth(false).applyTo(dateRangeClient);
    dateRangeClient.setEnabled(false);
    dateRangeClient.pack();

    final Label fromLabel = new Label(dateRangeClient, SWT.NONE);
    fromLabel.setText("From:");
    GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(fromLabel);
    fromDate = new DateTime(dateRangeClient, SWT.DATE | SWT.DROP_DOWN | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(fromDate);
    fromLabel.setEnabled(false);
    fromDate.setEnabled(false);

    fromDate.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            int day = fromDate.getDay();
            int month = fromDate.getMonth() + 1;
            int year = fromDate.getYear();
            Date newDate = null;
            try {
              newDate = format.parse(day + "/" + month + "/" + year);
            } catch (ParseException e) {
              e.printStackTrace();
            }

            if (newDate.before(minDate) || newDate.after(maxDate)) {
              Calendar cal = Calendar.getInstance();
              cal.setTime(minDate);
              fromDate.setMonth(cal.get(Calendar.MONTH));
              fromDate.setDay(cal.get(Calendar.DAY_OF_MONTH));
              fromDate.setYear(cal.get(Calendar.YEAR));
            }
          }
        });

    final Label toLabel = new Label(dateRangeClient, SWT.NONE);
    toLabel.setText("To:");
    GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(toLabel);
    toDate = new DateTime(dateRangeClient, SWT.DATE | SWT.DROP_DOWN | SWT.BORDER);
    GridDataFactory.fillDefaults().grab(false, false).span(1, 0).applyTo(toDate);
    toLabel.setEnabled(false);
    toDate.setEnabled(false);

    toDate.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            int day = toDate.getDay();
            int month = toDate.getMonth() + 1;
            int year = toDate.getYear();
            Date newDate = null;
            try {
              newDate = format.parse(day + "/" + month + "/" + year);
            } catch (ParseException e) {
              e.printStackTrace();
            }

            if (newDate.after(maxDate) || newDate.before(minDate)) {
              Calendar cal = Calendar.getInstance();
              cal.setTime(maxDate);
              toDate.setMonth(cal.get(Calendar.MONTH));
              toDate.setDay(cal.get(Calendar.DAY_OF_MONTH));
              toDate.setYear(cal.get(Calendar.YEAR));
            }
          }
        });

    Job loadFieldValuesJob =
        new Job("Loading form field values") {
          HashMap<String, String> congressDetails = null;
          final ArrayList<String> tempCongress = new ArrayList<String>();
          final ArrayList<String> tempCongressYears = new ArrayList<String>();

          @Override
          protected IStatus run(IProgressMonitor monitor) {
            try {
              congressDetails = AvailableRecords.getAllCongresses();
            } catch (IOException e) {
              e.printStackTrace();
            }
            Display.getDefault()
                .syncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        cmbCongress.removeAll();
                        for (String key : congressDetails.keySet()) {
                          tempCongress.add(key);
                          String value = congressDetails.get(key);
                          tempCongressYears.add(value);

                          cmbCongress.add(key + " (" + value + ")");

                          if (key.equalsIgnoreCase("All")) {
                            String[] tempYears = value.split("-");
                            Calendar cal = Calendar.getInstance();
                            cal.set(Integer.parseInt(tempYears[0]), 0, 1);
                            minDate = cal.getTime();
                            fromDate.setMonth(cal.get(Calendar.MONTH));
                            fromDate.setDay(cal.get(Calendar.DAY_OF_MONTH));
                            fromDate.setYear(cal.get(Calendar.YEAR));

                            cal.set(Integer.parseInt(tempYears[1]), 11, 31);
                            toDate.setMonth(cal.get(Calendar.MONTH));
                            toDate.setDay(cal.get(Calendar.DAY_OF_MONTH));
                            toDate.setYear(cal.get(Calendar.YEAR));
                            maxDate = cal.getTime();
                          }
                        }
                        // cmbCongress.setItems(congresses);
                        cmbCongress.select(0);
                      }
                    });
            congresses = tempCongress.toArray(new String[0]);
            congressYears = tempCongressYears.toArray(new String[0]);
            try {
              allSenators = AvailableRecords.getAllSenators(congresses);
              totalSenators = allSenators.length + 5;
              Display.getDefault()
                  .syncExec(
                      new Runnable() {
                        @Override
                        public void run() {
                          addSenatorBtn.setEnabled(true);
                        }
                      });
            } catch (IOException e2) {
              e2.printStackTrace();
            }
            return Status.OK_STATUS;
          }
        };
    // loadFieldValuesJob.setUser(true);
    loadFieldValuesJob.schedule();

    cmbCongress.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            // set dates
            String tempYears[] = congressYears[cmbCongress.getSelectionIndex()].split("-");
            Calendar cal = Calendar.getInstance();
            cal.set(Integer.parseInt(tempYears[0]), 0, 1);
            minDate = cal.getTime();
            fromDate.setMonth(cal.get(Calendar.MONTH));
            fromDate.setDay(cal.get(Calendar.DAY_OF_MONTH));
            fromDate.setYear(cal.get(Calendar.YEAR));

            cal.set(Integer.parseInt(tempYears[1]), 11, 31);
            toDate.setMonth(cal.get(Calendar.MONTH));
            toDate.setDay(cal.get(Calendar.DAY_OF_MONTH));
            toDate.setYear(cal.get(Calendar.YEAR));
            maxDate = cal.getTime();
            // cmbSenator.select(0);

            // Empty the senatorTable
            senatorTable.removeAll();
            selectedSenators = new ArrayList<String>();
          }
        });

    dateRange.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (dateRange.getSelection()) {
              dateRangeClient.setEnabled(true);
              fromLabel.setEnabled(true);
              fromDate.setEnabled(true);
              toLabel.setEnabled(true);
              toDate.setEnabled(true);
            } else {
              dateRangeClient.setEnabled(false);
              fromLabel.setEnabled(false);
              fromDate.setEnabled(false);
              toLabel.setEnabled(false);
              toDate.setEnabled(false);
            }
          }
        });

    limitRecords.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (limitRecords.getSelection()) {
              sortByDateYes.setEnabled(true);
              sortByDateNo.setEnabled(true);
              sortLabel.setEnabled(true);
              limitLabel.setEnabled(true);
              limitText.setEnabled(true);
            } else {
              sortByDateYes.setEnabled(false);
              sortByDateNo.setEnabled(false);
              sortLabel.setEnabled(false);
              limitLabel.setEnabled(false);
              limitText.setEnabled(false);
            }
          }
        });
  }
  protected Control createDialogArea(Composite parent) {
    parent.setBackground(EccTreeControl.color);
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_FOREGROUND));
    composite.setLayout(new FillLayout(SWT.HORIZONTAL));
    TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
    tabFolder.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_FOREGROUND));

    TabItem basicItem = new TabItem(tabFolder, SWT.NONE);
    basicItem.setText("基本");

    Composite composite1 = new Composite(tabFolder, SWT.NONE);
    composite1.setBackground(EccTreeControl.color);
    basicItem.setControl(composite1);

    SashForm sashForm = new SashForm(composite1, SWT.VERTICAL);
    sashForm.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    sashForm.setSize(445, 211);
    sashForm.setLocation(0, 0);

    Composite composite_1 = new Composite(sashForm, SWT.NONE);
    composite_1.setBackground(EccTreeControl.color);

    ICollection ico = FileTools.getBussCollection("TaskName", name, "EccTaskPlan");
    IEnumerator ien = ico.GetEnumerator();
    while (ien.MoveNext()) {
      bo = (BusinessObject) ien.get_Current();
      if (bo != null && bo.GetField("Model").get_NativeValue().toString().equals("绝对时间任务计划")) {
        TaskName = bo.GetField("TaskName").get_NativeValue().toString();
        Instruction = bo.GetField("Instruction").get_NativeValue().toString();
        StatrtTime = bo.GetField("StatrtTime").get_NativeValue().toString();
        String[] s2 = StatrtTime.split(";");
        String[] b1 = s2[0].split(",");
        time = b1[1];
        String[] b2 = s2[1].split(",");
        time_1 = b2[1];
        String[] b3 = s2[2].split(",");
        time_2 = b3[1];
        String[] b4 = s2[3].split(",");
        time_3 = b4[1];
        String[] b5 = s2[4].split(",");
        time_4 = b5[1];
        String[] b6 = s2[5].split(",");
        time_5 = b6[1];
        String[] b7 = s2[6].split(",");
        time_6 = b7[1];

        Status = bo.GetField("Status").get_NativeValue().toString();
        String[] s1 = Status.split(";");
        String[] a1 = s1[0].split(":");
        date = a1[0]; // 星期日
        permission = a1[1];
        String[] a2 = s1[1].split(":");
        date_1 = a2[0]; // 星期一
        permission_1 = a2[1];
        String[] a3 = s1[2].split(":");
        date_2 = a3[0]; // 星期二
        permission_2 = a3[1];
        String[] a4 = s1[3].split(":");
        date_3 = a4[0]; // 星期三
        permission_3 = a4[1];
        String[] a5 = s1[4].split(":");
        date_4 = a5[0]; // 星期四
        permission_4 = a5[1];
        String[] a6 = s1[5].split(":");
        date_5 = a6[0]; // 星期五
        permission_5 = a6[1];
        String[] a7 = s1[6].split(":");
        date_6 = a7[0]; // 星期六
        permission_6 = a7[1];
      }
    }

    text = new Text(composite_1, SWT.BORDER); // 任务计划名称
    text.setLocation(137, 0);
    text.setSize(177, 18);
    text.setText(TaskName);
    text.setEnabled(false);

    Label lblNewLabel = new Label(composite_1, SWT.NONE);
    lblNewLabel.setBackground(SWTResourceManager.getColor(SWT.COLOR_TITLE_FOREGROUND));
    lblNewLabel.setFont(SWTResourceManager.getFont("宋体", 10, SWT.NORMAL));
    lblNewLabel.setBounds(10, 2, 102, 18);
    lblNewLabel.setText("\u4EFB\u52A1\u8BA1\u5212\u540D\u79F0*:");

    Composite composite_2 = new Composite(sashForm, SWT.NONE);
    composite_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));

    lblNewLabel_1 = new Label(composite_2, SWT.NONE);
    lblNewLabel_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    lblNewLabel_1.setBounds(20, 10, 54, 16);
    lblNewLabel_1.setText("星期日");

    btnCheckButton = new Button(composite_2, SWT.CHECK);
    btnCheckButton.setBounds(102, 8, 45, 16);
    btnCheckButton.setBackground(EccTreeControl.color);
    btnCheckButton.setText("\u5141\u8BB8");
    if (lblNewLabel_1.getText().equals(date) && permission.equals("允许")) {
      btnCheckButton.setSelection(true);
    } else if (lblNewLabel_1.getText().equals(date) && permission.equals("禁止")) {
      btnCheckButton.setSelection(false);
    }

    final DateTime startTime = new DateTime(composite_2, SWT.TIME | SWT.SHORT);
    startTime.setLocation(164, 10);
    startTime.setSize(79, 15);
    int h = Integer.parseInt(time.substring(0, time.indexOf(":")));
    int m = Integer.parseInt(time.substring(time.indexOf(":") + 1, time.lastIndexOf(":")));
    int mm = Integer.parseInt(time.substring(time.lastIndexOf(":") + 1));
    startTime.setTime(h, m, mm);
    startTimeStr =
        startTime.getHours() + ":" + startTime.getMinutes() + ":" + startTime.getSeconds();
    startTime.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            startTimeStr =
                startTime.getHours() + ":" + startTime.getMinutes() + ":" + startTime.getSeconds();
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });

    lblNewLabel_2 = new Label(composite_2, SWT.NONE);
    lblNewLabel_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    lblNewLabel_2.setBounds(20, 32, 54, 16);
    lblNewLabel_2.setText("星期一");

    btnCheckButton_1 = new Button(composite_2, SWT.CHECK);
    btnCheckButton_1.setBounds(102, 30, 45, 16);
    btnCheckButton_1.setBackground(EccTreeControl.color);
    btnCheckButton_1.setText("\u5141\u8BB8");
    if (lblNewLabel_2.getText().equals(date_1) && permission_1.equals("允许")) {
      btnCheckButton_1.setSelection(true);
    } else if (lblNewLabel_2.getText().equals(date_1) && permission_1.equals("禁止")) {
      btnCheckButton_1.setSelection(false);
    }

    final DateTime startTime_1 = new DateTime(composite_2, SWT.TIME | SWT.SHORT);
    startTime_1.setLocation(164, 31);
    startTime_1.setSize(79, 15);
    int h1 = Integer.parseInt(time_1.substring(0, time_1.indexOf(":")));
    int m1 = Integer.parseInt(time_1.substring(time_1.indexOf(":") + 1, time_1.lastIndexOf(":")));
    int mm1 = Integer.parseInt(time_1.substring(time_1.lastIndexOf(":") + 1));
    startTime_1.setTime(h1, m1, mm1);
    startTimeStr_1 =
        startTime_1.getHours() + ":" + startTime_1.getMinutes() + ":" + startTime_1.getSeconds();
    startTime_1.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            startTimeStr_1 =
                startTime_1.getHours()
                    + ":"
                    + startTime_1.getMinutes()
                    + ":"
                    + startTime_1.getSeconds();
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });

    lblNewLabel_3 = new Label(composite_2, SWT.NONE);
    lblNewLabel_3.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    lblNewLabel_3.setBounds(20, 54, 54, 16);
    lblNewLabel_3.setText("星期二");

    btnCheckButton_2 = new Button(composite_2, SWT.CHECK);
    btnCheckButton_2.setBackground(EccTreeControl.color);
    btnCheckButton_2.setBounds(102, 51, 45, 16);
    btnCheckButton_2.setText("\u5141\u8BB8");
    if (lblNewLabel_3.getText().equals(date_2) && permission_2.equals("允许")) {
      btnCheckButton_2.setSelection(true);
    } else if (lblNewLabel_3.getText().equals(date_2) && permission_2.equals("禁止")) {
      btnCheckButton_2.setSelection(false);
    }

    final DateTime startTime_2 = new DateTime(composite_2, SWT.TIME | SWT.SHORT);
    startTime_2.setLocation(164, 52);
    startTime_2.setSize(79, 15);
    int h2 = Integer.parseInt(time_2.substring(0, time_2.indexOf(":")));
    int m2 = Integer.parseInt(time_2.substring(time_2.indexOf(":") + 1, time_2.lastIndexOf(":")));
    int mm2 = Integer.parseInt(time_2.substring(time_2.lastIndexOf(":") + 1));
    startTime_2.setTime(h2, m2, mm2);
    startTimeStr_2 =
        startTime_2.getHours() + ":" + startTime_2.getMinutes() + ":" + startTime_2.getSeconds();
    startTime_2.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            startTimeStr_2 =
                startTime_2.getHours()
                    + ":"
                    + startTime_2.getMinutes()
                    + ":"
                    + startTime_2.getSeconds();
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });

    lblNewLabel_4 = new Label(composite_2, SWT.NONE);
    lblNewLabel_4.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    lblNewLabel_4.setBounds(20, 76, 54, 16);
    lblNewLabel_4.setText("星期三");

    btnCheckButton_3 = new Button(composite_2, SWT.CHECK);
    btnCheckButton_3.setBackground(EccTreeControl.color);
    btnCheckButton_3.setBounds(102, 71, 45, 16);
    btnCheckButton_3.setText("\u5141\u8BB8");
    if (lblNewLabel_4.getText().equals(date_3) && permission_3.equals("允许")) {
      btnCheckButton_3.setSelection(true);
    } else if (lblNewLabel_4.getText().equals(date_3) && permission_3.equals("禁止")) {
      btnCheckButton_3.setSelection(false);
    }

    final DateTime startTime_3 = new DateTime(composite_2, SWT.TIME | SWT.SHORT);
    startTime_3.setLocation(164, 73);
    startTime_3.setSize(79, 15);
    int h3 = Integer.parseInt(time_3.substring(0, time_3.indexOf(":")));
    int m3 = Integer.parseInt(time_3.substring(time_3.indexOf(":") + 1, time_3.lastIndexOf(":")));
    int mm3 = Integer.parseInt(time_3.substring(time_3.lastIndexOf(":") + 1));
    startTime_3.setTime(h3, m3, mm3);
    startTimeStr_3 =
        startTime_3.getHours() + ":" + startTime_3.getMinutes() + ":" + startTime_3.getSeconds();
    startTimeStr_3 =
        startTime_3.getHours() + ":" + startTime_3.getMinutes() + ":" + startTime_3.getSeconds();
    startTime_3.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            startTimeStr_3 =
                startTime_3.getHours()
                    + ":"
                    + startTime_3.getMinutes()
                    + ":"
                    + startTime_3.getSeconds();
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });

    lblNewLabel_5 = new Label(composite_2, SWT.NONE);
    lblNewLabel_5.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    lblNewLabel_5.setBounds(20, 98, 54, 16);
    lblNewLabel_5.setText("星期四");

    button = new Button(composite_2, SWT.CHECK);
    button.setBackground(EccTreeControl.color);
    button.setText("\u5141\u8BB8");
    button.setBounds(102, 93, 45, 16);
    if (lblNewLabel_5.getText().equals(date_4) && permission_4.equals("允许")) {
      button.setSelection(true);
    } else if (lblNewLabel_5.getText().equals(date_4) && permission_4.equals("禁止")) {
      button.setSelection(false);
    }

    final DateTime startTime_4 = new DateTime(composite_2, SWT.TIME | SWT.SHORT);
    startTime_4.setLocation(164, 94);
    startTime_4.setSize(79, 15);
    int h4 = Integer.parseInt(time_4.substring(0, time_4.indexOf(":")));
    int m4 = Integer.parseInt(time_4.substring(time_4.indexOf(":") + 1, time_4.lastIndexOf(":")));
    int mm4 = Integer.parseInt(time_4.substring(time_4.lastIndexOf(":") + 1));
    startTime_4.setTime(h4, m4, mm4);
    startTimeStr_4 =
        startTime_4.getHours() + ":" + startTime_4.getMinutes() + ":" + startTime_4.getSeconds();
    startTime_4.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            startTimeStr_4 =
                startTime_4.getHours()
                    + ":"
                    + startTime_4.getMinutes()
                    + ":"
                    + startTime_4.getSeconds();
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });

    lblNewLabel_6 = new Label(composite_2, SWT.NONE);
    lblNewLabel_6.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    lblNewLabel_6.setBounds(20, 120, 54, 12);
    lblNewLabel_6.setText("星期五");
    btnCheckButton_4 = new Button(composite_2, SWT.CHECK);
    btnCheckButton_4.setBackground(EccTreeControl.color);
    btnCheckButton_4.setBounds(102, 115, 45, 16);
    btnCheckButton_4.setText("\u5141\u8BB8");
    if (lblNewLabel_6.getText().equals(date_5) && permission_5.equals("允许")) {
      btnCheckButton_4.setSelection(true);
    } else if (lblNewLabel_6.getText().equals(date_5) && permission_5.equals("禁止")) {
      btnCheckButton_4.setSelection(false);
    }

    final DateTime startTime_5 = new DateTime(composite_2, SWT.TIME | SWT.SHORT);
    startTime_5.setLocation(164, 115);
    startTime_5.setSize(79, 15);
    int h5 = Integer.parseInt(time_5.substring(0, time_5.indexOf(":")));
    int m5 = Integer.parseInt(time_5.substring(time_5.indexOf(":") + 1, time_5.lastIndexOf(":")));
    int mm5 = Integer.parseInt(time_5.substring(time_5.lastIndexOf(":") + 1));
    startTime_5.setTime(h5, m5, mm5);
    startTimeStr_5 =
        startTime_5.getHours() + ":" + startTime_5.getMinutes() + ":" + startTime_5.getSeconds();
    startTime_5.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            startTimeStr_5 =
                startTime_5.getHours()
                    + ":"
                    + startTime_5.getMinutes()
                    + ":"
                    + startTime_5.getSeconds();
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });

    lblNewLabel_7 = new Label(composite_2, SWT.NONE);
    lblNewLabel_7.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
    lblNewLabel_7.setBounds(20, 142, 54, 16);
    lblNewLabel_7.setText("星期六");

    btnCheckButton_5 = new Button(composite_2, SWT.CHECK);
    btnCheckButton_5.setBackground(EccTreeControl.color);
    btnCheckButton_5.setBounds(102, 137, 45, 16);
    btnCheckButton_5.setText("\u5141\u8BB8");
    if (lblNewLabel_7.getText().equals(date_6) && permission_6.equals("允许")) {
      btnCheckButton_5.setSelection(true);
    } else if (lblNewLabel_7.getText().equals(date_6) && permission_6.equals("禁止")) {
      btnCheckButton_5.setSelection(false);
    }

    final DateTime startTime_6 = new DateTime(composite_2, SWT.TIME | SWT.SHORT);
    startTime_6.setLocation(164, 136);
    startTime_6.setSize(79, 15);
    int h6 = Integer.parseInt(time_6.substring(0, time_6.indexOf(":")));
    int m6 = Integer.parseInt(time_6.substring(time_6.indexOf(":") + 1, time_6.lastIndexOf(":")));
    int mm6 = Integer.parseInt(time_6.substring(time_6.lastIndexOf(":") + 1));
    startTime_6.setTime(h6, m6, mm6);
    startTimeStr_6 =
        startTime_6.getHours() + ":" + startTime_6.getMinutes() + ":" + startTime_6.getSeconds();
    startTime_6.addSelectionListener(
        new SelectionListener() {
          public void widgetSelected(SelectionEvent e) {
            startTimeStr_6 =
                startTime_6.getHours()
                    + ":"
                    + startTime_6.getMinutes()
                    + ":"
                    + startTime_6.getSeconds();
          }

          public void widgetDefaultSelected(SelectionEvent e) {}
        });

    sashForm.setWeights(new int[] {1, 8});

    TabItem describeItem = new TabItem(tabFolder, SWT.NONE);
    describeItem.setText("描述");

    Composite composite2 = new Composite(tabFolder, SWT.NONE);
    composite2.setBackground(EccTreeControl.color);
    describeItem.setControl(composite2);
    composite2.setLayout(new BorderLayout(0, 0));

    Label label = new Label(composite2, SWT.HORIZONTAL);
    label.setAlignment(SWT.CENTER);
    label.setBackground(EccTreeControl.color);
    label.setBounds(0, 0, 54, 199);
    label.setLayoutData(BorderLayout.WEST);
    label.setText("\u63CF\u8FF0\uFF1A");

    text1 = new Text(composite2, SWT.WRAP | SWT.BORDER); // 描述
    text1.setLayoutData(BorderLayout.CENTER);
    text1.setText(Instruction);

    return composite;
  }
  /**
   * Create contents of the dialog.
   *
   * @param parent
   */
  @Override
  protected Control createDialogArea(Composite parent) {

    getShell().setText("Geleistete Arbeit anlegen oder anpassen");

    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new FillLayout(SWT.HORIZONTAL));

    parentForm = formToolkit.createForm(container);
    formToolkit.paintBordersFor(parentForm);
    formToolkit.decorateFormHeading(parentForm);
    parentForm.setText("Geleistete Arbeit anlegen oder anpassen");

    IToolBarManager toolbar = parentForm.getToolBarManager();
    Action reuseSelectionAction = new InternalReuseEntryAction();
    toolbar.add(reuseSelectionAction);
    toolbar.update(true);

    parentForm.getBody().setLayout(new GridLayout(1, false));

    Composite composite = formToolkit.createComposite(parentForm.getBody(), SWT.NONE);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    formToolkit.paintBordersFor(composite);
    composite.setLayout(new GridLayout(4, false));

    Label dateLabel = new Label(composite, SWT.NONE);
    dateLabel.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
    formToolkit.adapt(dateLabel, true, true);
    dateLabel.setText("Datum");

    dateTime = new DateTime(composite, SWT.BORDER | SWT.CALENDAR);
    formToolkit.adapt(dateTime);
    formToolkit.paintBordersFor(dateTime);

    Label timeLabel = new Label(composite, SWT.NONE);
    timeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
    formToolkit.adapt(timeLabel, true, true);
    timeLabel.setText("Dauer (in h)");

    timeText = new Text(composite, SWT.NONE);
    timeText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
    formToolkit.adapt(timeText, true, true);

    Label workLabel = new Label(composite, SWT.NONE);
    workLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    formToolkit.adapt(workLabel, true, true);
    workLabel.setText("Tätigkeit");

    workComboViewer = new ComboViewer(composite, SWT.NONE);
    Combo workCombo = workComboViewer.getCombo();
    workCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    formToolkit.paintBordersFor(workCombo);

    Label personLabel = new Label(composite, SWT.NONE);
    personLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    formToolkit.adapt(personLabel, true, true);
    personLabel.setText("Person");

    personComboViewer = new ComboViewer(composite, SWT.NONE);
    Combo personCombo = personComboViewer.getCombo();
    personCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    formToolkit.paintBordersFor(personCombo);

    Label commentLabel = new Label(composite, SWT.NONE);
    commentLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
    formToolkit.adapt(commentLabel, true, true);
    commentLabel.setText("Bemerkungen");

    commentText = new Text(composite, SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
    GridData gd_commentText = new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1);
    gd_commentText.heightHint = 50;
    commentText.setLayoutData(gd_commentText);
    formToolkit.adapt(commentText, true, true);

    Label label = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData gd_label = new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1);
    gd_label.heightHint = 10;
    label.setLayoutData(gd_label);
    formToolkit.adapt(label, true, true);

    bandTypeLabel = new Label(composite, SWT.NONE);
    bandTypeLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    formToolkit.adapt(bandTypeLabel, true, true);
    bandTypeLabel.setText("Band Typ");

    bandTypeComboViewer = new ComboViewer(composite, SWT.NONE);
    bandTypeCombo = bandTypeComboViewer.getCombo();
    bandTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    formToolkit.paintBordersFor(bandTypeCombo);

    amountLabel = new Label(composite, SWT.NONE);
    amountLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    formToolkit.adapt(amountLabel, true, true);
    amountLabel.setText("Anzahl");

    amountText = new Text(composite, SWT.NONE);
    amountText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    formToolkit.adapt(amountText, true, true);

    new Label(composite, SWT.NONE);
    new Label(composite, SWT.NONE);

    trackLink = new Link(composite, SWT.NONE);
    trackLink.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    formToolkit.adapt(trackLink, true, true);
    trackLink.setText("<a>Bahn(en)</a>");

    trackText = new Text(composite, SWT.NONE);
    trackText.setEditable(false);
    trackText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    formToolkit.adapt(trackText, true, true);

    bandTypeLabel.setEnabled(false);
    bandTypeCombo.setEnabled(false);
    amountLabel.setEnabled(false);
    amountText.setEnabled(false);
    trackLink.setEnabled(false);
    trackText.setEnabled(false);

    DefaultStructuredContentProvider provider = new DefaultStructuredContentProvider();
    workComboViewer.setContentProvider(provider);
    personComboViewer.setContentProvider(provider);
    bandTypeComboViewer.setContentProvider(provider);

    InternalLabelProvider labelProvider = new InternalLabelProvider();
    workComboViewer.setLabelProvider(labelProvider);
    personComboViewer.setLabelProvider(labelProvider);
    bandTypeComboViewer.setLabelProvider(labelProvider);

    if (root.getWorks() != null && !root.getWorks().getWork().isEmpty()) {
      if (bandActionOnly) {
        workComboViewer.addFilter(new IntenalViewerFilter());
      }
      workComboViewer.setInput(root.getWorks().getWork());
    } else {
      workLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
    }
    if (root.getPersons() != null && !root.getPersons().getPerson().isEmpty()) {
      personComboViewer.setInput(root.getPersons().getPerson());
    } else {
      personLabel.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
    }

    bandTypeComboViewer.setInput(BandTypes.values());

    if (editMode) {
      if (entry.getDate() != null) {
        Calendar c = Calendar.getInstance();
        c.setTime(entry.getDate());
        dateTime.setDate(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DATE));
      }
      if (entry.getTime() != null) {
        timeText.setText("" + entry.getTime());
      }
      if (entry.getComment() != null) {
        commentText.setText(entry.getComment());
      }
      if (entry.getPersonId() != null) {
        PersonType pt = null;
        if (root.getPersons() != null) {
          for (PersonType p : root.getPersons().getPerson()) {
            if (p.getId().equals(entry.getPersonId())) {
              pt = p;
              break;
            }
          }
        }
        if (pt != null) {
          StructuredSelection s = new StructuredSelection(pt);
          personComboViewer.setSelection(s);
          currentPersonType = pt;
        }
        personCombo.setEnabled(false);
      }
      if (entry.getWorkId() != null) {
        WorkType wt = null;
        if (root.getWorks() != null) {
          for (WorkType w : root.getWorks().getWork()) {
            if (w.getId().equals(entry.getWorkId())) {
              wt = w;
              break;
            }
          }
        }
        if (wt != null) {
          StructuredSelection s = new StructuredSelection(wt);
          workComboViewer.setSelection(s);
          currentWorkType = wt;
        }
        workCombo.setEnabled(false);
      }
      if (entry.getBandAction() != null) {
        if (entry.getBandAction().getBandType() != null) {
          StructuredSelection s = new StructuredSelection(entry.getBandAction().getBandType());
          bandTypeComboViewer.setSelection(s);
        }
        bandTypeLabel.setEnabled(true);
        bandTypeCombo.setEnabled(true);
        if (entry.getBandAction().getAmount() != null) {
          amountText.setText("" + entry.getBandAction().getAmount());
        }
        amountLabel.setEnabled(true);
        amountText.setEnabled(true);
        trackText.setText(getTrackString(entry.getBandAction()));
        trackLink.setEnabled(true);
        trackText.setEnabled(true);
      }
    }

    ModifyListener modifyListener =
        new ModifyListener() {
          @Override
          public void modifyText(ModifyEvent e) {
            if (e.widget == timeText) {
              entry.setTime(!timeText.getText().isEmpty() ? Float.valueOf(timeText.getText()) : 0);
            } else if (e.widget == commentText) {
              entry.setComment(!commentText.getText().isEmpty() ? commentText.getText() : null);
            } else if (e.widget == amountText) {
              if (entry.getBandAction() == null)
                entry.setBandAction(factory.createBandActionType());
              if (!amountText.getText().isEmpty()) {
                entry.getBandAction().setAmount(Integer.parseInt(amountText.getText()));
              } else {
                entry.getBandAction().setAmount(null);
              }
            }
          }
        };
    timeText.addModifyListener(modifyListener);
    commentText.addModifyListener(modifyListener);
    amountText.addModifyListener(modifyListener);

    SelectionAdapter selectionAdapter =
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (e.widget == dateTime) {
              Calendar c = Calendar.getInstance();
              c.set(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay());
              entry.setDate(c.getTime());
            } else if (e.widget == trackLink) {
              InternalTrackSelectionDialog dialog =
                  new InternalTrackSelectionDialog(getShell(), entry.getBandAction());
              if (InternalTrackSelectionDialog.OK == dialog.open()) {
                BandActionType ba = dialog.getBandAction();
                if (entry.getBandAction() == null) entry.setBandAction(ba);
                else {
                  entry.getBandAction().getTrack().clear();
                  entry.getBandAction().getTrack().addAll(ba.getTrack());
                }
                trackText.setText(getTrackString(entry.getBandAction()));
              }
            }
          }
        };
    dateTime.addSelectionListener(selectionAdapter);
    trackLink.addSelectionListener(selectionAdapter);

    ISelectionChangedListener seleChangedListener =
        new ISelectionChangedListener() {
          @Override
          public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSource() == workComboViewer) {
              WorkType wt =
                  (WorkType)
                      ((IStructuredSelection) workComboViewer.getSelection()).getFirstElement();
              if (wt != null) {
                currentWorkType = wt;
                entry.setWorkId(wt.getId());
                if (wt.isAffectBand() != null && wt.isAffectBand()) {
                  bandTypeLabel.setEnabled(true);
                  bandTypeCombo.setEnabled(true);
                  amountLabel.setEnabled(true);
                  amountText.setEnabled(true);
                  trackLink.setEnabled(true);
                  trackText.setEnabled(true);
                } else {
                  bandTypeLabel.setEnabled(false);
                  bandTypeCombo.setEnabled(false);
                  amountLabel.setEnabled(false);
                  amountText.setEnabled(false);
                  trackLink.setEnabled(false);
                  trackText.setEnabled(false);
                }
              } else {
                currentWorkType = null;
              }
            } else if (event.getSource() == personComboViewer) {
              PersonType pt =
                  (PersonType)
                      ((IStructuredSelection) personComboViewer.getSelection()).getFirstElement();
              if (pt != null) {
                currentPersonType = pt;
                entry.setPersonId(pt.getId());
              } else {
                currentPersonType = null;
              }
            } else if (event.getSource() == bandTypeComboViewer) {
              BandTypes bt =
                  (BandTypes)
                      ((IStructuredSelection) bandTypeComboViewer.getSelection()).getFirstElement();
              if (entry.getBandAction() == null)
                entry.setBandAction(factory.createBandActionType());
              if (bt != null) {
                entry.getBandAction().setBandType(bt);
              } else {
                entry.getBandAction().setBandType(null);
              }
            }
          }
        };
    workComboViewer.addSelectionChangedListener(seleChangedListener);
    personComboViewer.addSelectionChangedListener(seleChangedListener);
    bandTypeComboViewer.addSelectionChangedListener(seleChangedListener);

    return container;
  }
  @Override
  protected void okPressed() {

    if (currentWorkType == null) {
      parentForm.setMessage("Wählen Sie eine Tätigkeit!", IMessageProvider.ERROR);
      return;
    } else {
      if (currentWorkType.isAffectBand() == null || !currentWorkType.isAffectBand()) {
        entry.setBandAction(null);
      } else {
        if (entry.getBandAction() == null) {
          parentForm.setMessage("Unbekanntes Problem bei Bändern!", IMessageProvider.ERROR);
          return;
        }
        if (entry.getBandAction().getBandType() == null) {
          parentForm.setMessage("Kein Bandtyp ausgewählt!", IMessageProvider.ERROR);
          return;
        }
        if (entry.getBandAction().getAmount() == null || entry.getBandAction().getAmount() == 0) {
          boolean confirm =
              MessageDialog.openQuestion(
                  getShell(),
                  "Anzahl bestätigen",
                  "Sie wollen bei einer Tätigkeit, die ein oder mehrere Bänder betreffen kann, eine Anzahl von '0' angeben...\n"
                      + "Sind Sie sich sicher?");
          if (confirm) entry.getBandAction().setAmount(0);
          else return;
        }
      }
    }

    if (currentPersonType == null) {
      parentForm.setMessage("Wählen Sie eine Person!", IMessageProvider.ERROR);
      return;
    }

    if (entry.getDate() == null) {
      Calendar c = Calendar.getInstance();
      c.set(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay());
      entry.setDate(c.getTime());
    }
    Calendar c = Calendar.getInstance();
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.add(Calendar.DATE, +1);
    if (entry.getDate() == null || c.getTime().before(entry.getDate())) {
      parentForm.setMessage("Kein Datum, oder Datum in der Zukunft!", IMessageProvider.ERROR);
      return;
    }

    if (entry.getTime() == null || entry.getTime() == 0) {
      boolean confirm =
          MessageDialog.openQuestion(
              getShell(),
              "Dauer bestätigen",
              "Sie wollen bei einer Tätigkeit, eine Dauer von '0' Stunden angeben...\n"
                  + "Sind Sie sich sicher?");
      if (confirm) entry.setTime(new Float(0));
      else return;
    }

    super.okPressed();
  }
  @Override
  public void createPartControl(Composite parent) {
    Activator.getDefault()
        .getPreferenceStore()
        .addPropertyChangeListener(
            new IPropertyChangeListener() {

              @Override
              public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty() == "selectedfont") {
                  FontData[] fonts = (FontData[]) event.getNewValue();

                  Font font = new Font(Display.getDefault(), fonts[0]);

                  setFont(newPatientVisitComposite, font);
                }
              }
            });

    final Composite composite = new Composite(parent, SWT.NONE);
    GridLayout compositeGL = new GridLayout(1, true);
    composite.setLayout(compositeGL);
    GridData compositeGD = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH);
    composite.setLayoutData(compositeGD);
    composite.setSize(composite.computeSize(parent.getSize().x, SWT.DEFAULT));

    scrolledComposite = new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    scrolledComposite.setExpandHorizontal(true);
    scrolledComposite.setExpandVertical(true);
    GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH);
    scrolledComposite.setLayoutData(data);
    scrolledComposite.setSize(scrolledComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

    newPatientVisitComposite = new Composite(scrolledComposite, SWT.NULL);
    GridLayout newPatientVisitCompositeGL = new GridLayout(1, false);
    newPatientVisitComposite.setLayout(newPatientVisitCompositeGL);
    GridData newPatientVisitCompositeGD = new GridData(GridData.FILL_BOTH);
    newPatientVisitComposite.setLayoutData(newPatientVisitCompositeGD);

    Group newPatientGroup = new Group(newPatientVisitComposite, SWT.NULL);
    newPatientGroup.setText("New / Search patient");
    GridLayout newPatientGroupGL = new GridLayout(4, true);
    newPatientGroup.setLayout(newPatientGroupGL);
    GridData newPatientGroupGD = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
    newPatientGroupGD.verticalIndent = 0;
    newPatientGroup.setLayoutData(newPatientGroupGD);

    // new patient / search components
    Button radioButtonNewPatient = new Button(newPatientGroup, SWT.RADIO);
    radioButtonNewPatient.setText("New Patient");
    GridData radioBtnNewPatientGD = new GridData();
    radioBtnNewPatientGD.horizontalSpan = 2;
    radioButtonNewPatient.setLayoutData(radioBtnNewPatientGD);

    Button radioButtonSearch = new Button(newPatientGroup, SWT.RADIO);
    radioButtonSearch.setText("Search");
    GridData radioBtnSearchGD = new GridData();
    radioBtnSearchGD.horizontalSpan = 2;
    radioButtonSearch.setLayoutData(radioBtnSearchGD);

    Label lblName = new Label(newPatientGroup, SWT.NONE);
    lblName.setText("Name");
    GridData lblNameGD = new GridData();
    lblNameGD.horizontalSpan = 3;
    lblNameGD.verticalIndent = 5;
    lblName.setLayoutData(lblNameGD);

    Label lblId = new Label(newPatientGroup, SWT.NONE);
    lblId.setText("ID");
    GridData lblIdGD = new GridData();
    lblIdGD.horizontalSpan = 1;
    lblIdGD.verticalIndent = 5;
    lblId.setLayoutData(lblIdGD);

    textName = new Text(newPatientGroup, SWT.BORDER);
    GridData txtNameGD = new GridData(GridData.FILL_HORIZONTAL);
    txtNameGD.horizontalSpan = 3;
    txtNameGD.grabExcessHorizontalSpace = true;
    textName.setLayoutData(txtNameGD);

    textID = new Text(newPatientGroup, SWT.BORDER);
    GridData txtIDGD = new GridData(GridData.FILL_HORIZONTAL);
    txtIDGD.grabExcessHorizontalSpace = true;
    textID.setLayoutData(txtIDGD);

    Label lblStudyType = new Label(newPatientGroup, SWT.NONE);
    lblStudyType.setText("Study Type:");
    GridData lblStudyTypeGD = new GridData();
    lblStudyTypeGD.verticalIndent = 5;
    lblStudyType.setLayoutData(lblStudyTypeGD);

    final Combo selectStudyTypeForSearchingCombo = new Combo(newPatientGroup, SWT.READ_ONLY);
    GridData selectStudyTypeForSearchingComboGD = new GridData(GridData.FILL_HORIZONTAL);
    selectStudyTypeForSearchingComboGD.horizontalSpan = 2;
    selectStudyTypeForSearchingComboGD.verticalIndent = 5;
    selectStudyTypeForSearchingComboGD.grabExcessHorizontalSpace = true;
    selectStudyTypeForSearchingCombo.setLayoutData(selectStudyTypeForSearchingComboGD);

    final Button buttonSaveSearch = new Button(newPatientGroup, SWT.NONE);
    GridData buttonSaveSearchGD = new GridData(GridData.FILL_HORIZONTAL);
    buttonSaveSearchGD.horizontalSpan = 1;
    buttonSaveSearchGD.verticalIndent = 5;
    buttonSaveSearchGD.grabExcessHorizontalSpace = true;
    buttonSaveSearch.setLayoutData(buttonSaveSearchGD);
    buttonSaveSearch.setText("Save");

    // search result components
    final TableViewer tableViewer =
        new TableViewer(newPatientGroup, SWT.BORDER | SWT.FULL_SELECTION);
    tableViewer.setColumnProperties(new String[] {"Name", "ID"});
    Table table = tableViewer.getTable();
    GridData tableGD = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    tableGD.grabExcessHorizontalSpace = true;
    tableGD.horizontalSpan = 4;
    tableGD.verticalIndent = 10;
    tableGD.heightHint = 125;
    table.setLayoutData(tableGD);

    // select study combo
    Label lblSelectStudy = new Label(newPatientGroup, SWT.NONE);
    lblSelectStudy.setText("Select Study");
    GridData lblSelectStudyGD = new GridData();
    lblSelectStudyGD.verticalIndent = 5;
    lblSelectStudy.setLayoutData(lblSelectStudyGD);

    final ComboViewer selectStudyFromSearchResultsComboViewer =
        new ComboViewer(newPatientGroup, SWT.READ_ONLY);
    GridData selectStudyFromSearchResultsComboViewerGD = new GridData(GridData.FILL_HORIZONTAL);
    selectStudyFromSearchResultsComboViewerGD.horizontalSpan = 3;
    selectStudyFromSearchResultsComboViewerGD.verticalIndent = 5;
    selectStudyFromSearchResultsComboViewerGD.grabExcessHorizontalSpace = true;
    selectStudyFromSearchResultsComboViewer
        .getControl()
        .setLayoutData(selectStudyFromSearchResultsComboViewerGD);

    // select series combo
    Label lblSelectSeries = new Label(newPatientGroup, SWT.NONE);
    lblSelectSeries.setText("Select Series");
    GridData lblSelectSeriesGD = new GridData();
    lblSelectSeriesGD.verticalIndent = 5;
    lblSelectSeries.setLayoutData(lblSelectSeriesGD);

    final ComboViewer selectSeriesComboViewer = new ComboViewer(newPatientGroup, SWT.READ_ONLY);
    GridData selectSeriesComboViewerGD = new GridData(GridData.FILL_HORIZONTAL);
    selectSeriesComboViewerGD.horizontalSpan = 3;
    selectSeriesComboViewerGD.verticalIndent = 5;
    selectSeriesComboViewerGD.grabExcessHorizontalSpace = true;
    selectSeriesComboViewer.getCombo().setLayoutData(selectSeriesComboViewerGD);

    // new study controls
    Group newStudyGroup = new Group(newPatientVisitComposite, SWT.NULL);
    newStudyGroup.setText("New Study");
    GridLayout newStudyGroupGL = new GridLayout(4, true);
    newStudyGroup.setLayout(newStudyGroupGL);
    GridData newStudyGroupGD = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
    newStudyGroupGD.verticalIndent = 10;
    newStudyGroup.setLayoutData(newStudyGroupGD);

    Label lblNewStudyName = new Label(newStudyGroup, SWT.NONE);
    lblNewStudyName.setText("Study Name");
    GridData lblNewStudyNameGD = new GridData();
    lblNewStudyNameGD.verticalIndent = 5;
    lblNewStudyName.setLayoutData(lblNewStudyNameGD);

    final Text newStudyNameText = new Text(newStudyGroup, SWT.BORDER);
    GridData newStudyNameTextGD = new GridData(GridData.FILL_HORIZONTAL);
    newStudyNameTextGD.horizontalSpan = 3;
    newStudyNameTextGD.verticalIndent = 5;
    newStudyNameTextGD.grabExcessHorizontalSpace = true;
    newStudyNameText.setLayoutData(newStudyNameTextGD);

    Label lblNewStudyType = new Label(newStudyGroup, SWT.NONE);
    lblNewStudyType.setText("Study Type:");
    GridData lblNewStudyTypeGD = new GridData();
    lblNewStudyTypeGD.verticalIndent = 5;
    lblNewStudyType.setLayoutData(lblNewStudyTypeGD);

    final Combo selectNewStudyTypeCombo = new Combo(newStudyGroup, SWT.READ_ONLY);
    GridData selectNewStudyTypeComboGD = new GridData(GridData.FILL_HORIZONTAL);
    selectNewStudyTypeComboGD.horizontalSpan = 2;
    selectNewStudyTypeComboGD.verticalIndent = 5;
    selectNewStudyTypeComboGD.grabExcessHorizontalSpace = true;
    selectNewStudyTypeCombo.setLayoutData(selectNewStudyTypeComboGD);

    final DateTime newStudyDateTimeDate =
        new DateTime(newStudyGroup, SWT.BORDER | SWT.DATE | SWT.DROP_DOWN);
    GridData dateTimeDateGD = new GridData(GridData.FILL_HORIZONTAL);
    dateTimeDateGD.grabExcessHorizontalSpace = true;
    dateTimeDateGD.verticalIndent = 5;
    newStudyDateTimeDate.setLayoutData(dateTimeDateGD);

    final Button btnSaveStudy = new Button(newStudyGroup, SWT.NONE);
    GridData btnSaveStudyGD = new GridData(GridData.FILL_HORIZONTAL);
    btnSaveStudyGD.horizontalSpan = 1;
    btnSaveStudyGD.verticalIndent = 5;
    btnSaveStudyGD.grabExcessHorizontalSpace = true;
    btnSaveStudy.setLayoutData(btnSaveStudyGD);
    btnSaveStudy.setText("Save Study");

    // new series controls
    Group newSeriesGroup = new Group(newPatientVisitComposite, SWT.NULL);
    newSeriesGroup.setText("New Series");
    GridLayout newSeriesGroupGL = new GridLayout(4, true);
    newSeriesGroup.setLayout(newSeriesGroupGL);
    GridData newSeriesGroupGD = new GridData(GridData.GRAB_HORIZONTAL | GridData.FILL_HORIZONTAL);
    newSeriesGroupGD.verticalIndent = 10;
    newSeriesGroup.setLayoutData(newSeriesGroupGD);

    Label lblNewSeriesName = new Label(newSeriesGroup, SWT.NONE);
    lblNewSeriesName.setText("Series Name");
    GridData lblNewSeriesNameGD = new GridData();
    lblNewSeriesNameGD.verticalIndent = 5;
    lblNewSeriesName.setLayoutData(lblNewSeriesNameGD);

    final Text newSeriesNameText = new Text(newSeriesGroup, SWT.BORDER);
    GridData newSeriesNameTextGD = new GridData(GridData.FILL_HORIZONTAL);
    newSeriesNameTextGD.horizontalSpan = 3;
    newSeriesNameTextGD.verticalIndent = 5;
    newSeriesNameTextGD.grabExcessHorizontalSpace = true;
    newSeriesNameText.setLayoutData(newSeriesNameTextGD);

    Label lblNewSeriesTime = new Label(newSeriesGroup, SWT.NONE);
    lblNewSeriesTime.setText("Series Date Time");
    GridData lblNewSeriesTimeGD = new GridData();
    lblNewSeriesTimeGD.verticalIndent = 5;
    lblNewSeriesTime.setLayoutData(lblNewSeriesTimeGD);

    final DateTime newSeriesDateTimeDate =
        new DateTime(newSeriesGroup, SWT.BORDER | SWT.DATE | SWT.DROP_DOWN);
    GridData seriesDateGD = new GridData();
    seriesDateGD.horizontalSpan = 1;
    //		seriesDateGD.grabExcessHorizontalSpace = true;
    seriesDateGD.verticalIndent = 5;
    newSeriesDateTimeDate.setLayoutData(seriesDateGD);

    final DateTime newSeriesDateTimeTime =
        new DateTime(newSeriesGroup, SWT.BORDER | SWT.TIME | SWT.DROP_DOWN);
    GridData seriesTimeGD = new GridData();
    seriesTimeGD.horizontalSpan = 1;
    //		seriesTimeGD.grabExcessHorizontalSpace = true;
    seriesTimeGD.verticalIndent = 5;
    newSeriesDateTimeTime.setLayoutData(seriesTimeGD);

    Label placeHolder = new Label(newSeriesGroup, SWT.NONE);
    GridData placeHolderGD = new GridData(GridData.FILL_HORIZONTAL);
    placeHolderGD.horizontalSpan = 1;
    placeHolderGD.grabExcessHorizontalSpace = true;
    placeHolder.setLayoutData(placeHolderGD);

    Label lblNewSeriesDescription = new Label(newSeriesGroup, SWT.NONE);
    lblNewSeriesDescription.setText("Series Description");
    GridData lblNewSeriesDescriptionGD = new GridData();
    lblNewSeriesDescriptionGD.grabExcessVerticalSpace = true;
    lblNewSeriesDescriptionGD.verticalSpan = 15;
    lblNewSeriesDescriptionGD.verticalAlignment = SWT.BEGINNING;
    lblNewSeriesDescriptionGD.verticalIndent = 5;
    lblNewSeriesDescription.setLayoutData(lblNewSeriesDescriptionGD);

    final Text newSeriesNameDescription =
        new Text(newSeriesGroup, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
    GridData newSeriesNameDescriptionGD =
        new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    newSeriesNameDescriptionGD.horizontalSpan = 3;
    newSeriesNameDescriptionGD.verticalIndent = 5;
    newSeriesNameDescriptionGD.verticalSpan = 15;
    newSeriesNameDescriptionGD.grabExcessHorizontalSpace = true;
    newSeriesNameDescription.setLayoutData(newSeriesNameDescriptionGD);

    Label lblPhotosLocation = new Label(newSeriesGroup, SWT.NONE);
    lblPhotosLocation.setText("Photos Location");
    GridData lblPhotosLocationGD = new GridData();
    lblPhotosLocationGD.horizontalSpan = 1;
    lblPhotosLocationGD.verticalIndent = 5;
    lblPhotosLocation.setLayoutData(lblPhotosLocationGD);

    final Text textPhotosLocation = new Text(newSeriesGroup, SWT.BORDER);
    GridData textPhotosLocationGD = new GridData(GridData.FILL_HORIZONTAL);
    textPhotosLocationGD.horizontalSpan = 1;
    textPhotosLocationGD.verticalIndent = 5;
    textPhotosLocationGD.grabExcessHorizontalSpace = true;
    textPhotosLocation.setLayoutData(textPhotosLocationGD);

    final Button buttonBrowse = new Button(newSeriesGroup, SWT.NONE);
    GridData btnBrowseGD = new GridData(GridData.FILL_HORIZONTAL);
    btnBrowseGD.horizontalSpan = 1;
    btnBrowseGD.verticalIndent = 5;
    btnBrowseGD.grabExcessHorizontalSpace = true;
    buttonBrowse.setLayoutData(btnBrowseGD);
    buttonBrowse.setText("Browse");

    final Button buttonLoad = new Button(newSeriesGroup, SWT.NONE);
    GridData btnLoadGD = new GridData(GridData.FILL_HORIZONTAL);
    btnLoadGD.horizontalSpan = 1;
    btnLoadGD.verticalIndent = 5;
    btnLoadGD.grabExcessHorizontalSpace = true;
    buttonLoad.setLayoutData(btnLoadGD);
    buttonLoad.setText("Load");

    final Button buttnoSaveSeries = new Button(newSeriesGroup, SWT.NONE);
    GridData btnSaveSeriesGD = new GridData(GridData.FILL_HORIZONTAL);
    btnSaveSeriesGD.horizontalSpan = 1;
    btnSaveSeriesGD.verticalIndent = 5;
    btnSaveSeriesGD.grabExcessHorizontalSpace = true;
    buttnoSaveSeries.setLayoutData(btnSaveSeriesGD);
    buttnoSaveSeries.setText("Save Series");

    // set defaults
    radioButtonNewPatient.setSelection(true);
    selectStudyTypeForSearchingCombo.setEnabled(false);
    tableViewer.getTable().setEnabled(false);
    selectStudyFromSearchResultsComboViewer.getControl().setEnabled(false);
    selectSeriesComboViewer.getControl().setEnabled(false);

    // set size
    Point size = newPatientVisitComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    scrolledComposite.setMinSize(size);
    scrolledComposite.setContent(newPatientVisitComposite);
    scrolledComposite.layout(true);

    scrolledComposite.addListener(
        SWT.Activate,
        new Listener() {
          public void handleEvent(Event e) {
            scrolledComposite.setFocus();
          }
        });

    final IPatientService pService =
        (IPatientService) PlatformUI.getWorkbench().getService(IPatientService.class);

    // browse button clicked
    buttonBrowse.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            final FileDialog dialog = new FileDialog(getSite().getShell(), SWT.OPEN | SWT.MULTI);
            final String lastSelectedFilePath = dialog.open();
            // create the structure for files
            Display.getDefault()
                .asyncExec(
                    new Runnable() {
                      @Override
                      public void run() {
                        String[] selectedFileNames = dialog.getFileNames();
                        if (selectedFileNames != null && selectedFileNames.length > 0) {
                          textPhotosLocation.setText(lastSelectedFilePath);
                          String dirName =
                              lastSelectedFilePath.substring(
                                  0, lastSelectedFilePath.lastIndexOf(File.separator) + 1);
                          if (loadedPhotosList != null) {
                            loadedPhotosList.clear();
                          } else {
                            loadedPhotosList = new ArrayList<String>();
                          }
                          for (String selectedFileName : selectedFileNames) {
                            loadedPhotosList.add(dirName.concat(selectedFileName));
                          }
                        }
                      }
                    });
          }
        });

    // load button clicked
    buttonLoad.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            loadPhotos();
          }
        });

    // save radio selected
    radioButtonNewPatient.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            selectStudyTypeForSearchingCombo.setEnabled(false);
            tableViewer.getTable().setEnabled(false);
            selectStudyFromSearchResultsComboViewer.getControl().setEnabled(false);
            selectSeriesComboViewer.getControl().setEnabled(false);
            buttonSaveSearch.setText("Save");
          }
        });

    // search radio selected
    radioButtonSearch.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            selectStudyTypeForSearchingCombo.setEnabled(true);
            tableViewer.getTable().setEnabled(true);
            selectStudyFromSearchResultsComboViewer.getControl().setEnabled(true);
            selectSeriesComboViewer.getControl().setEnabled(true);
            buttonSaveSearch.setText("Search");
          }
        });

    buttonSaveSearch.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            if (buttonSaveSearch.getText().equals("Save")) {
              String newPatientName = textName.getText();
              String ID = textID.getText();

              if (newPatientName == null || "".equals(newPatientName)) {
                Util.showMessage("Name can't be empty!");
                return;
              }

              if (ID == null || "".equals(ID)) {
                ID = String.valueOf(UUID.randomUUID().getMostSignificantBits());
              }

              IPatient newPatient = PatientFactory.getInstance().create(ID, newPatientName, null);

              //					IPatientService pservice = Activator.getDefault().getPatientService();
              if (pService != null) {
                IStatus status = null;
                try {
                  status = pService.saveNewPatient(newPatient);
                } catch (IOException e1) {
                  e1.printStackTrace();
                }

                if (status == Status.OK_STATUS) {
                  //							StatusLineContribution slc = (StatusLineContribution)
                  // Activator.getDefault().getStatusItem();
                  //							slc.setText("Active Patient : " + newPatient.getName());
                  //							slc.setVisible(true);
                  updateStatus("Active Patient : " + newPatient.getName());

                  activePatient = newPatient;

                  textName.setText("");
                  textID.setText("");

                } else {
                  // XXX log
                }
              } else {
                Util.showMessage("Patient service is null :-(");
              }
            } else {
              String searchName = textName.getText();
              String searchID = textID.getText();
              //					IPatientService pService = Activator.getDefault().getPatientService();

              try {
                List<IPatient> patientSearchResults = pService.searchPatients(searchName, searchID);

                if (patientSearchResults != null) {

                  tableViewer.setContentProvider(new ArrayContentProvider());
                  tableViewer.getTable().setLinesVisible(true);
                  tableViewer.getTable().setHeaderVisible(true);
                  // create columns
                  createPatientColumns(tableViewer);

                  // set input
                  tableViewer.setInput(patientSearchResults);

                  tableViewer.refresh();
                } else {
                  // XXX log and inform user null was returned
                }
              } catch (Exception e1) {
                //						StatusLineContribution slc = (StatusLineContribution)
                // Activator.getDefault().getStatusItem();
                //						slc.setText("Active Patient : " + e1.getMessage());
                //						slc.setVisible(true);
                updateStatus("Active Patient : " + e1.getMessage());
              }
            }
          }
        });

    btnSaveStudy.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            IStudy newStudy = StudyFactory.getInstance().create(null);
            newStudy.setStudyName(newStudyNameText.getText());

            // get selected date for new study
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DAY_OF_MONTH, newStudyDateTimeDate.getDay());
            calendar.set(Calendar.MONTH, newStudyDateTimeDate.getMonth());
            calendar.set(Calendar.YEAR, newStudyDateTimeDate.getYear());

            Date studyDate = calendar.getTime();

            newStudy.setStudyDate(studyDate);
            newStudy.setStudyType(selectNewStudyTypeCombo.getText());
            newStudy.setPatientID(activePatient.getId());
            newStudy.setNumberOfSeries((Integer) 0);
            newStudy.setStudyID(String.valueOf(UUID.randomUUID().getLeastSignificantBits()));

            //				IPatientService pService = Activator.getDefault().getPatientService();
            IStatus status = null;
            try {
              status = pService.saveNewStudy(newStudy);
            } catch (IOException e1) {
              e1.printStackTrace();
            }

            if (status == Status.OK_STATUS) {
              activeStudy = newStudy;

              String statusLineText =
                  "Active Patient : "
                      + activePatient.getName()
                      + " Active Study : "
                      + activeStudy.toString();

              updateStatus(statusLineText);

              //					StatusLineContribution slc = (StatusLineContribution)
              // Activator.getDefault().getStatusItem();
              //					slc.setText(statusLineText);
              //					slc.setVisible(true);

              newStudyNameText.setText("");
              selectNewStudyTypeCombo.clearSelection();
            } else {
              // XXX log
            }
          }
        });

    buttnoSaveSeries.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {

            ISeries newSeries = SeriesFactory.getInstance().create(null);
            newSeries.setSeriesName(newSeriesNameText.getText());
            newSeries.setNotes(newSeriesNameDescription.getText());
            newSeries.setParentStudyID("");
            newSeries.setPhotos(selectedPhotosFilesList);
            newSeries.setSeriesID(String.valueOf(UUID.randomUUID().getMostSignificantBits()));
            newSeries.setParentStudyID(activeStudy.getStudyID());

            // get selected date for new study
            Calendar calendar = Calendar.getInstance();
            //				calendar.set(Calendar.DAY_OF_MONTH, newSeriesDateTimeTime.getDay());
            //				calendar.set(Calendar.MONTH, newSeriesDateTimeTime.getMonth());
            //				calendar.set(Calendar.YEAR, newSeriesDateTimeTime.getYear());

            calendar.set(Calendar.DAY_OF_MONTH, newSeriesDateTimeDate.getDay());
            calendar.set(Calendar.MONTH, newSeriesDateTimeDate.getMonth());
            calendar.set(Calendar.YEAR, newSeriesDateTimeDate.getYear());

            calendar.set(Calendar.HOUR_OF_DAY, newSeriesDateTimeTime.getHours());
            calendar.set(Calendar.MINUTE, newSeriesDateTimeTime.getMinutes());
            calendar.set(Calendar.SECOND, newSeriesDateTimeTime.getSeconds());

            newSeries.setSeriesTime(calendar.getTime());

            //				IPatientService pService = Activator.getDefault().getPatientService();
            IStatus status = null;
            try {
              status = pService.saveNewSeries(newSeries);
            } catch (IOException e1) {
              e1.printStackTrace();
            }

            if (status == Status.OK_STATUS) {
              // clear UI fileds
              newSeriesNameText.setText("");
              newSeriesNameDescription.setText("");
              textPhotosLocation.setText("");

            } else {
              // XXX log
            }
          };
        });

    tableViewer
        .getTable()
        .addSelectionListener(
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                StructuredSelection selection = (StructuredSelection) tableViewer.getSelection();
                if (selection.getFirstElement() instanceof IPatient) {
                  IPatient selectedPatient = (IPatient) selection.getFirstElement();

                  activePatient = selectedPatient;

                  //					StatusLineContribution slc = (StatusLineContribution)
                  // Activator.getDefault().getStatusItem();
                  //					slc.setText("Active Patient : " + activePatient.getName());
                  //					slc.setVisible(true);

                  updateStatus("Active Patient : " + activePatient.getName());

                  selectSeriesComboViewer.getCombo().clearSelection();
                  selectSeriesComboViewer.getCombo().removeAll();

                  // get all studies of this patient
                  //					IPatientService pService = Activator.getDefault().getPatientService();
                  try {
                    List<IStudy> studiesForSelectedpatient =
                        pService.getStudiesForPatient(selectedPatient);
                    selectStudyFromSearchResultsComboViewer.setContentProvider(
                        ArrayContentProvider.getInstance());
                    selectStudyFromSearchResultsComboViewer.setLabelProvider(
                        new LabelProvider() {
                          public String getText(Object element) {
                            return ((IStudy) element).toString();
                          };
                        });
                    selectStudyFromSearchResultsComboViewer.setInput(studiesForSelectedpatient);
                  } catch (Exception e1) {
                    updateStatus(e1.getMessage());
                    //						slc.setText(e1.getMessage());
                    //						slc.setVisible(true);
                  }
                }
              }
            });

    selectStudyFromSearchResultsComboViewer
        .getCombo()
        .addSelectionListener(
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                StructuredSelection selection =
                    (StructuredSelection) selectStudyFromSearchResultsComboViewer.getSelection();
                if (selection.getFirstElement() instanceof IStudy) {
                  IStudy selectedStudy = (IStudy) selection.getFirstElement();
                  activeStudy = selectedStudy;
                  //					StatusLineContribution slc = (StatusLineContribution)
                  // Activator.getDefault().getStatusItem();
                  //					slc.setText("Active Patient : " + activePatient.getName() +
                  //								  " Active Study : " + activeStudy.toString());
                  //					slc.setVisible(true);
                  updateStatus(
                      "Active Patient : "
                          + activePatient.getName()
                          + " Active Study : "
                          + activeStudy.toString());

                  // get all series for this study
                  //					IPatientService pService = Activator.getDefault().getPatientService();
                  try {
                    List<ISeries> seriesForSelectedStudy =
                        pService.getSeriesForStudy(selectedStudy);
                    selectSeriesComboViewer.setContentProvider(ArrayContentProvider.getInstance());
                    selectSeriesComboViewer.setLabelProvider(
                        new LabelProvider() {
                          public String getText(Object element) {
                            return ((ISeries) element).toString();
                          };
                        });
                    selectSeriesComboViewer.setInput(seriesForSelectedStudy);
                    selectSeriesComboViewer.refresh();
                  } catch (Exception e1) {
                    //						slc.setText(e1.getMessage());
                    updateStatus(e1.getMessage());
                  }
                }
              }
            });

    selectSeriesComboViewer
        .getCombo()
        .addSelectionListener(
            new SelectionAdapter() {
              @Override
              public void widgetSelected(SelectionEvent e) {
                StructuredSelection selection =
                    (StructuredSelection) selectSeriesComboViewer.getSelection();
                if (selection.getFirstElement() instanceof ISeries) {
                  ISeries selectedSeries = (ISeries) selection.getFirstElement();

                  if (loadedPhotosList != null) {
                    loadedPhotosList.clear();
                  } else {
                    loadedPhotosList = new ArrayList<String>();
                  }

                  // load photos for selected series
                  for (Object selectedFileName : selectedSeries.getPhotos()) {
                    loadedPhotosList.add(selectedFileName.toString());
                  }
                  loadPhotos();
                }
              }
            });
  }