Пример #1
0
  private void initialize() {
    String filename = StringUtils.defaultString(level.getName());
    GridData gridDataLabel = new GridData();
    gridDataLabel.widthHint = 100;
    gridDataLabel.verticalAlignment = GridData.CENTER;
    gridDataLabel.horizontalAlignment = GridData.END;
    GridData gridDataText = new GridData();
    gridDataText.heightHint = -1;
    gridDataText.widthHint = 150;
    GridLayout gridLayoutMy = new GridLayout();
    gridLayoutMy.numColumns = 2;
    gridLayoutMy.marginWidth = 25;
    gridLayoutMy.verticalSpacing = 5;
    gridLayoutMy.horizontalSpacing = 20;
    gridLayoutMy.marginHeight = 25;
    gridLayoutMy.makeColumnsEqualWidth = false;
    GridData gridDataMy = new GridData();
    gridDataMy.grabExcessHorizontalSpace = true;
    gridDataMy.verticalAlignment = GridData.CENTER;
    gridDataMy.horizontalSpan = 1;
    gridDataMy.horizontalAlignment = GridData.FILL;
    this.setLayoutData(gridDataMy);
    this.setLayout(gridLayoutMy);
    Label labelTitle = new Label(this, SWT.RIGHT);
    labelTitle.setText(
        "*   ".concat(LabelHolder.get("dialog.pojo.level.fields.title"))); // $NON-NLS-1$
    labelTitle.setLayoutData(gridDataLabel);
    textTitle = new Text(this, SWT.BORDER);
    textTitle.setTextLimit(256);
    textTitle.setLayoutData(gridDataText);
    textTitle.setText(StringUtils.defaultString(level.getTitle()));
    Label labelName = new Label(this, SWT.RIGHT);
    labelName.setText(
        "*   ".concat(LabelHolder.get("dialog.pojo.level.fields.name"))); // $NON-NLS-1$
    labelName.setLayoutData(gridDataLabel);
    textName = new Text(this, SWT.BORDER);
    textName.setTextLimit(256);
    textName.setLayoutData(gridDataText);
    textName.setText(filename);
    textName.addVerifyListener(new FileNameVerifier());
    textName.addModifyListener(new ModifyListenerClearErrorMessages(dialogCreator));

    Collection<String> forbiddenNames = new ArrayList<String>();
    Collection<Level> sisters = level.getParent().getSublevels();
    if (CollectionUtils.isNotEmpty(sisters))
      for (Level otherLevel : sisters) forbiddenNames.add(otherLevel.getName());
    if (StringUtils.isNotBlank(filename)) forbiddenNames.remove(filename);
    if (level.getId()
        == APoormansObject
            .UNSET_VALUE) // suggestion of the file name should work just with new  objects
    textTitle.addModifyListener(
          new FilenameSuggestorListener(dialogCreator, textName, forbiddenNames));
  }
Пример #2
0
 /*
  * (non-Javadoc)
  * @see de.thischwa.pmcms.gui.workspace.dialog.IValidator#isValid()
  */
 @Override
 public boolean isValid() {
   if (StringUtils.isBlank(textName.getText())) {
     dialogCreator.setErrorMessage(
         LabelHolder.get("dialog.pojo.level.error.name.notvalid")); // $NON-NLS-1$
     return false;
   } else if (existsName()) {
     dialogCreator.setErrorMessage(
         LabelHolder.get("dialog.pojo.level.error.name.exists")); // $NON-NLS-1$
     return false;
   }
   if (StringUtils.isBlank(textTitle.getText())) {
     dialogCreator.setErrorMessage(
         LabelHolder.get("dialog.pojo.level.error.title")); // $NON-NLS-1$
     return false;
   }
   level.setName(textName.getText());
   level.setTitle(textTitle.getText());
   return true;
 }