示例#1
0
文件: UserUI.java 项目: venom02/TESI
  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");
  }
示例#2
0
  /**
   * 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;
  }
示例#3
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);
  }