コード例 #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;
  }
コード例 #2
0
  /**
   * @param parent
   * @return composite the page
   * @since 4.0
   */
  @SuppressWarnings({"unused", "unchecked"})
  Composite createPageControl(final Composite parent) {
    // Create page
    final Composite mainPanel = new Composite(parent, SWT.NONE);
    mainPanel.setLayout(new GridLayout(COLUMN_COUNT, false));
    // Add widgets to page
    WidgetFactory.createLabel(mainPanel, FOLDER_LABEL);
    final String name =
        (this.folder == null ? null : this.folder.getFullPath().makeRelative().toString());
    this.folderText =
        WidgetFactory.createTextField(mainPanel, GridData.FILL_HORIZONTAL, 1, name, SWT.READ_ONLY);
    this.folderText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(final ModifyEvent event) {
            folderModified();
          }
        });
    btnBrowse = WidgetFactory.createButton(mainPanel, BROWSE_BUTTON);
    btnBrowse.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(final SelectionEvent event) {
            browseButtonSelected();
          }
        });
    WidgetFactory.createLabel(mainPanel, NAME_LABEL);
    this.nameText =
        WidgetFactory.createTextField(mainPanel, GridData.HORIZONTAL_ALIGN_FILL, COLUMN_COUNT - 1);
    this.nameText.addModifyListener(
        new ModifyListener() {
          @Override
          public void modifyText(final ModifyEvent event) {
            nameModified();
          }
        });

    // set focus to browse button if no folder selected. otherwise set focus to text field
    if (folder == null) {
      btnBrowse.setFocus();
    } else {
      nameText.setFocus();
    }

    DESCRIPTION_GROUP:
    {
      final Group descGroup =
          WidgetFactory.createGroup(
              mainPanel, getString("description"), GridData.FILL_HORIZONTAL, 3); // $NON-NLS-1$
      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 = 50;
      descGridData.minimumHeight = 30;
      descGridData.grabExcessVerticalSpace = true;
      descriptionTextEditor.setLayoutData(descGridData);
      descriptionTextEditor.setText(""); // $NON-NLS-1$
    }

    MODELS_GROUP:
    {
      Group group =
          WidgetFactory.createGroup(
              mainPanel,
              getString("selectedModelsGroupTitle"),
              GridData.FILL_BOTH,
              COLUMN_COUNT,
              COLUMN_COUNT); //$NON-NLS-1$
      group.setLayout(new GridLayout(2, false));
      GridData gd = new GridData(GridData.FILL_BOTH);
      gd.heightHint = 200;
      gd.horizontalSpan = 3;
      group.setLayoutData(gd);

      Composite leftToolbarPanel = new Composite(group, SWT.NONE);
      leftToolbarPanel.setLayout(new GridLayout());
      GridData ltpGD = new GridData(GridData.FILL_VERTICAL);
      ltpGD.heightHint = 120;
      leftToolbarPanel.setLayoutData(ltpGD);

      addModelsButton = new Button(leftToolbarPanel, SWT.PUSH);
      addModelsButton.setText(getString("add")); // $NON-NLS-1$
      addModelsButton.setToolTipText(getString("addModelsTooltip")); // $NON-NLS-1$
      addModelsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      addModelsButton.addSelectionListener(
          new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              handleAddModelsSelected();
              if (!modelsViewer.getSelection().isEmpty()) {
                removeModelsButton.setEnabled(true);
              }
            }
          });

      removeModelsButton = new Button(leftToolbarPanel, SWT.PUSH);
      removeModelsButton.setText(getString("remove")); // $NON-NLS-1$
      removeModelsButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
      removeModelsButton.setEnabled(false);
      removeModelsButton.addSelectionListener(
          new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
              Collection<IResource> models = new ArrayList<IResource>();

              IStructuredSelection selection = (IStructuredSelection) modelsViewer.getSelection();
              for (Object obj : selection.toArray()) {
                if (obj instanceof IResource) {
                  models.add((IResource) obj);
                }
              }
              removeModels(models);
              removeModelsButton.setEnabled(false);
            }
          });

      this.modelsViewer = new TableViewer(group);
      GridData gdv = new GridData(GridData.FILL_BOTH);
      // gdv.horizontalSpan = COLUMN_COUNT;
      modelsViewer.getControl().setLayoutData(gdv);
      modelsViewer.setContentProvider(new ListContentProvider());
      modelsViewer.setLabelProvider(new ModelExplorerLabelProvider());
      // Add Models from properties if available
      if (this.designerProperties != null && !this.designerProperties.isEmpty()) {
        IFile sourceMdl = DesignerPropertiesUtil.getSourceModel(this.designerProperties);
        IFile viewMdl = DesignerPropertiesUtil.getViewModel(this.designerProperties);
        if (sourceMdl != null) this.modelsForVdb.add(sourceMdl);
        if (viewMdl != null) this.modelsForVdb.add(viewMdl);
      } else {
        this.modelsForVdb.addAll(SelectionUtilities.getSelectedIResourceObjects(initialSelection));
      }
      modelsViewer.setInput(this.modelsForVdb);
      modelsViewer.addSelectionChangedListener(
          new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
              removeModelsButton.setEnabled(!event.getSelection().isEmpty());
            }
          });
    }

    updateForProperties();
    return mainPanel;
  }