コード例 #1
0
  @SuppressWarnings("unused")
  @Override
  protected Control createDialogArea(Composite parent) {
    creatingContents = true;
    if (isEdit) {
      setTitle(EDIT_TITLE);
    } else {
      setTitle(CREATE_TITLE);
    }

    Composite dialogComposite = (Composite) super.createDialogArea(parent);

    Composite composite = WidgetFactory.createPanel(dialogComposite);
    // ------------------------------
    // Set layout for the Composite
    // ------------------------------
    GridLayout gridLayout = new GridLayout();
    composite.setLayout(gridLayout);
    gridLayout.numColumns = 2;
    GridData gridData = new GridData(GridData.FILL_BOTH);
    gridData.grabExcessHorizontalSpace = true;
    gridData.widthHint = 500;
    composite.setLayoutData(gridData);

    Label label = new Label(composite, SWT.NONE | SWT.RIGHT);
    label.setText(UILabelUtil.getLabel(UiLabelConstants.LABEL_IDS.NAME));
    label.setLayoutData(new GridData());

    final Text indexNameText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    indexNameText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
    indexNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    indexNameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(final ModifyEvent event) {
            String value = indexNameText.getText();
            if (value == null) {
              value = EMPTY_STRING;
            }
            editedIndex.setName(value);
            validate();
          }
        });

    label = new Label(composite, SWT.NONE | SWT.RIGHT);
    label.setText(Messages.nameInSourceLabel);
    label.setLayoutData(new GridData());

    final Text indexNISText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    indexNISText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
    indexNISText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    indexNISText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(final ModifyEvent event) {
            String value = indexNISText.getText();
            if (value == null) {
              value = EMPTY_STRING;
            }
            editedIndex.setNameInSource(value);
            validate();
          }
        });

    // Group to present properties widgets
    PROPERTIES_GROUP:
    {
      this.autoUpdateCB = new Button(composite, SWT.CHECK | SWT.RIGHT);
      this.autoUpdateCB.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
      this.autoUpdateCB.setText(Messages.autoUpdateLabel);
      this.autoUpdateCB.addSelectionListener(
          new SelectionAdapter() {
            /**
             * {@inheritDoc}
             *
             * @see
             *     org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            @Override
            public void widgetSelected(SelectionEvent e) {
              editedIndex.setAutoUpdate(autoUpdateCB.getSelection());
              validate();
            }
          });
      new Label(composite, SWT.NONE);

      this.nullableCB = new Button(composite, SWT.CHECK | SWT.RIGHT);
      this.nullableCB.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
      this.nullableCB.setText(Messages.nullableLabel);
      this.nullableCB.addSelectionListener(
          new SelectionAdapter() {
            /**
             * {@inheritDoc}
             *
             * @see
             *     org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            @Override
            public void widgetSelected(SelectionEvent e) {
              editedIndex.setNullable(nullableCB.getSelection());
              validate();
            }
          });
      new Label(composite, SWT.NONE);

      this.uniqueCB = new Button(composite, SWT.CHECK | SWT.RIGHT);
      this.uniqueCB.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
      this.uniqueCB.setText(Messages.uniqueLabel);
      this.uniqueCB.addSelectionListener(
          new SelectionAdapter() {
            /**
             * {@inheritDoc}
             *
             * @see
             *     org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
             */
            @Override
            public void widgetSelected(SelectionEvent e) {
              editedIndex.setUnique(uniqueCB.getSelection());
              validate();
            }
          });
      new Label(composite, SWT.NONE);

      label = new Label(composite, SWT.NONE | SWT.RIGHT);
      label.setText(Messages.filterConditionLabel);
      label.setLayoutData(new GridData());

      filterConditionText = new Text(composite, SWT.BORDER | SWT.SINGLE);
      filterConditionText.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_DARK_BLUE));
      filterConditionText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      filterConditionText.addModifyListener(
          new ModifyListener() {
            @Override
            public void modifyText(final ModifyEvent event) {
              String value = filterConditionText.getText();
              if (value == null) {
                value = EMPTY_STRING;
              }
              editedIndex.setFilterCondition(value);
              validate();
            }
          });
    }

    Group theColumnsGroup =
        WidgetFactory.createGroup(
            dialogComposite, Messages.selectColumnReferencesForIndex, SWT.NONE, 1, 1);
    theColumnsGroup.setLayout(new GridLayout(1, false));
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 120;
    gd.widthHint = 500;
    theColumnsGroup.setLayoutData(gd);

    Table tableWidget =
        new Table(
            theColumnsGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.CHECK);
    tableWidget.setHeaderVisible(false);
    tableWidget.setLinesVisible(true);
    tableWidget.setLayout(new TableLayout());
    tableWidget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    theColumnDataViewer = new TableViewer(tableWidget);
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = 160;
    gd.horizontalSpan = 2;
    theColumnDataViewer.getControl().setLayoutData(gd);
    theColumnDataViewer.setContentProvider(
        new ITreeContentProvider() {

          @Override
          public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            // TODO Auto-generated method stub
          }

          @Override
          public void dispose() {
            // TODO Auto-generated method stub
          }

          @Override
          public boolean hasChildren(Object element) {
            return !theTable.getColumns().isEmpty();
          }

          @Override
          public Object getParent(Object element) {
            return null;
          }

          @Override
          public Object[] getElements(Object inputElement) {
            if (inputElement instanceof RelationalTable) {
              return theTable.getColumns().toArray(new Object[0]);
            }
            return new Object[0];
          }

          @Override
          public Object[] getChildren(Object parentElement) {
            // TODO Auto-generated method stub
            return new Object[0];
          }
        });

    this.theColumnDataViewer
        .getTable()
        .addSelectionListener(
            new SelectionListener() {

              @Override
              public void widgetSelected(SelectionEvent e) {
                editedIndex.getColumns().clear();
                for (TableItem item : theColumnDataViewer.getTable().getItems()) {

                  if (item.getChecked()) {
                    editedIndex.addColumn((RelationalColumn) item.getData());
                  }
                }
                validate();
              }

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

    theColumnDataViewer.setLabelProvider(new ColumnDataLabelProvider(0));

    theColumnDataViewer.setInput(this.theTable);

    for (RelationalColumn col : this.editedIndex.getColumns()) {
      for (TableItem item : theColumnDataViewer.getTable().getItems()) {
        if (item.getData() == col) {
          item.setChecked(true);
        }
      }
    }

    DESCRIPTION_GROUP:
    {
      final Group descGroup =
          WidgetFactory.createGroup(
              dialogComposite,
              UILabelUtil.getLabel(UiLabelConstants.LABEL_IDS.DESCRIPTION),
              GridData.FILL_BOTH,
              3);
      descriptionTextEditor =
          new StyledTextEditor(
              descGroup, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP | SWT.BORDER);
      final GridData descGridData = new GridData(GridData.FILL_BOTH);
      descGridData.horizontalSpan = 1;
      descGridData.heightHint = 120;
      //            descGridData.minimumHeight = 30;
      descGridData.grabExcessVerticalSpace = true;
      descriptionTextEditor.setLayoutData(descGridData);
      descriptionTextEditor.setText(""); // $NON-NLS-1$
      descriptionTextEditor
          .getTextWidget()
          .addModifyListener(
              new ModifyListener() {

                @Override
                public void modifyText(ModifyEvent e) {
                  editedIndex.setDescription(descriptionTextEditor.getText());
                }
              });
    }

    setMessage(Messages.newIndexMessage);
    if (editedIndex.getName() != null) {
      indexNameText.setText(editedIndex.getName());
    }
    if (editedIndex.getNameInSource() != null) {
      indexNISText.setText(editedIndex.getNameInSource());
    }
    this.autoUpdateCB.setSelection(editedIndex.isAutoUpdate());
    this.nullableCB.setSelection(editedIndex.isNullable());
    this.uniqueCB.setSelection(editedIndex.isUnique());
    if (editedIndex.getFilterCondition() != null) {
      filterConditionText.setText(editedIndex.getFilterCondition());
    }
    if (editedIndex.getDescription() != null) {
      descriptionTextEditor.setText(editedIndex.getDescription());
    }

    creatingContents = false;

    return composite;
  }