private void disposeControls(IFieldEditor editor) {
   if (editor != null) {
     Object[] controls = editor.getEditorControls();
     for (int i = 0; i < controls.length; i++) {
       Control control = (Control) controls[i];
       if (!control.isDisposed()) control.dispose();
     }
     editor.dispose();
   }
 }
  /** Finish has been pressed. */
  @SuppressWarnings("deprecation")
  public void transferStateToConfig() {
    String seamRuntimeName = jBossSeamHomeEditor.getValueAsString();
    SeamRuntime seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(seamRuntimeName);
    if (seamRuntime != null) {
      SeamRuntimeManager.getInstance().setDefaultRuntime(seamRuntime);
    }

    if (connProfileSelEditor != null) {
      SeamCorePlugin.getDefault()
          .getPluginPreferences()
          .setValue(
              SeamProjectPreferences.SEAM_DEFAULT_CONNECTION_PROFILE,
              connProfileSelEditor.getValueAsString());
    } else {
      SeamCorePlugin.getDefault()
          .getPluginPreferences()
          .setValue(
              SeamProjectPreferences.SEAM_DEFAULT_CONNECTION_PROFILE, getJpaConnectionProfile());
      model.setStringProperty(
          ISeamFacetDataModelProperties.SEAM_CONNECTION_PROFILE, getJpaConnectionProfile());
    }

    if (jBossHibernateDbTypeEditor != null) {
      SeamCorePlugin.getDefault()
          .getPluginPreferences()
          .setValue(
              SeamProjectPreferences.HIBERNATE_DEFAULT_DB_TYPE,
              this.jBossHibernateDbTypeEditor.getValueAsString());
    }

    SeamCorePlugin.getDefault()
        .getPluginPreferences()
        .setValue(
            SeamProjectPreferences.JBOSS_AS_DEFAULT_DEPLOY_AS,
            this.jBossAsDeployAsEditor.getValueAsString());

    model.setBooleanProperty(
        ISeamFacetDataModelProperties.SEAM_TEMPLATES_AND_LIBRARIES_COPYING,
        isSeamProjectWizard() || isWebProjectWizard());

    model.setBooleanProperty(
        ISeamFacetDataModelProperties.SEAM_RUNTIME_LIBRARIES_COPYING,
        libraryListEditor
                .getValueAsString()
                .equals(SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_COPY_LIBRARIES)
            && (isSeamProjectWizard() || isWebProjectWizard()));
  }
  protected void createFieldPanel(Composite parent) {
    IFieldEditor header = JQueryFieldEditorFactory.createCollapsibleHeaderEditor();
    header.setValue("Header");
    addEditor(header, parent);

    Composite[] columns = NewRangeSliderWizardPage.createTwoColumns(parent);
    Composite left = columns[0];
    Composite right = columns[1];

    IFieldEditor fieldSet = JQueryFieldEditorFactory.createFieldSetEditor();
    addEditor(fieldSet, left);

    IFieldEditor collapsed = JQueryFieldEditorFactory.createCollapsedEditor();
    addEditor(collapsed, right);

    IFieldEditor mini = JQueryFieldEditorFactory.createMiniEditor();
    addEditor(mini, left);

    IFieldEditor inset = JQueryFieldEditorFactory.createInsetEditor();
    addEditor(inset, right);

    createSeparator(parent);

    IFieldEditor collapsedIcon = JQueryFieldEditorFactory.createCollapsedIconEditor();
    addEditor(collapsedIcon, parent, true);

    IFieldEditor expandedIcon = JQueryFieldEditorFactory.createExpandedIconEditor();
    addEditor(expandedIcon, parent, true);

    IFieldEditor iconpos = JQueryFieldEditorFactory.createIconPositionEditor();
    addEditor(iconpos, parent, true);

    createSeparator(parent);

    IFieldEditor theme = JQueryFieldEditorFactory.createDataThemeEditor();
    addEditor(theme, parent, true);

    IFieldEditor contentTheme = JQueryFieldEditorFactory.createDataContentThemeEditor();
    addEditor(contentTheme, parent, true);

    inset.setValue(TRUE);
  }
 private boolean canTestProjectBeCreated() {
   if (isSeamProjectWizard()) {
     String seamRuntimeName = jBossSeamHomeEditor.getValueAsString();
     SeamRuntime seamRuntime = SeamRuntimeManager.getInstance().findRuntimeByName(seamRuntimeName);
     if (seamRuntime != null) {
       // bootstrap folder was removed in Seam 2.3.0.Beta1 from WFK 2.0 ER4
       // See https://issues.jboss.org/browse/JBIDE-11611
       File bootstrap = new File(seamRuntime.getHomeDir(), "bootstrap");
       return bootstrap.exists();
     }
   }
   return false;
 }
  public void propertyChanged(DataModelEvent event) {
    if (event.getPropertyName().equals(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER)) {
      model.setStringProperty(
          ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER, event.getProperty().toString());
    } else if (event.getPropertyName().equals(IFacetDataModelProperties.FACET_PROJECT_NAME)) {
      String seamProjectName = event.getProperty().toString();

      model.setStringProperty(ISeamFacetDataModelProperties.SEAM_PROJECT_NAME, seamProjectName);

      sessionBeanPkgNameditor.setValue(getSessionPkgName(seamProjectName));
      entityBeanPkgNameditor.setValue(getEntityPkgName(seamProjectName));
      testsPkgNameditor.setValue(getTestPkgName(seamProjectName));
      if (!isWebProjectWizard()) {
        ejbProjectNameditor.setValue(getEJBProjectName(seamProjectName));
        earProjectNameditor.setValue(getEARProjectName(seamProjectName));
      }
      testProjectNameditor.setValue(getTestProjectName(seamProjectName));

      model.setStringProperty(
          ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME,
          getSessionPkgName(seamProjectName));
      model.setStringProperty(
          ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME,
          getEntityPkgName(seamProjectName));
      model.setProperty(
          ISeamFacetDataModelProperties.TEST_PROJECT_CREATING,
          createTestProjectCheckboxeditor.getValue());
      model.setStringProperty(
          ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME, getTestPkgName(seamProjectName));
      model.setStringProperty(
          ISeamFacetDataModelProperties.SEAM_EAR_PROJECT, earProjectNameditor.getValueAsString());
      model.setStringProperty(
          ISeamFacetDataModelProperties.SEAM_EJB_PROJECT, ejbProjectNameditor.getValueAsString());
      model.setStringProperty(
          ISeamFacetDataModelProperties.SEAM_TEST_PROJECT, testProjectNameditor.getValueAsString());
    }
  }
  public void testNewGroupedButtonsBarWizard() {
    IWizardPage currentPage = runToolEntry("Grouped Buttons", true);

    assertTrue(currentPage instanceof NewGroupedButtonsWizardPage);

    NewGroupedButtonsWizardPage wizardPage = (NewGroupedButtonsWizardPage) currentPage;
    NewGroupedButtonsWizard wizard = (NewGroupedButtonsWizard) wizardPage.getWizard();

    assertTextDoesNotExist(wizard, DATA_TYPE_HORIZONTAL);
    wizardPage.setEditorValue(EDITOR_ID_LAYOUT, LAYOUT_HORIZONTAL);
    assertAttrExists(wizard, ATTR_DATA_TYPE, DATA_TYPE_HORIZONTAL);
    wizardPage.setEditorValue(EDITOR_ID_LAYOUT, LAYOUT_VERTICAL);
    assertTextDoesNotExist(wizard, DATA_TYPE_HORIZONTAL);

    assertEquals("3", wizardPage.getEditorValue(EDITOR_ID_NUMBER_OF_ITEMS));

    wizardPage.setEditorValue(EDITOR_ID_NUMBER_OF_ITEMS, "4");
    assertEquals("4", wizardPage.getEditorValue(EDITOR_ID_NUMBER_OF_ITEMS));
    IFieldEditor iconPos =
        ((CompositeEditor) wizardPage.getEditor(EDITOR_ID_ICON_POS)).getEditors().get(0);
    IFieldEditor icononly =
        ((CompositeEditor) wizardPage.getEditor(EDITOR_ID_ICON_ONLY)).getEditors().get(0);
    assertFalse(iconPos.isEnabled());
    assertFalse(icononly.isEnabled());
    wizardPage.setEditorValue(EDITOR_ID_ICON, "delete");
    assertTrue(iconPos.isEnabled());
    assertTrue(icononly.isEnabled());
    assertTextDoesNotExist(wizard, ATTR_DATA_ICONPOS);
    wizardPage.setEditorValue(EDITOR_ID_ICON_POS, "right");
    assertAttrExists(wizard, ATTR_DATA_ICONPOS, "right");
    wizardPage.setEditorValue(EDITOR_ID_ICON_ONLY, TRUE);
    assertAttrExists(wizard, ATTR_DATA_ICONPOS, ICONPOS_NOTEXT);

    doTestMini(wizardPage, wizard);

    compareGeneratedAndInsertedText(wizard);
  }
  /*
   * Fills Code Generation group with the default package names.
   */
  private void setCodeGenerationProperties() {
    String seamProjectName =
        model.getStringProperty(ISeamFacetDataModelProperties.SEAM_PROJECT_NAME);

    if (seamProjectName == null) return;

    if ("".equals(sessionBeanPkgNameditor.getValueAsString()))
      sessionBeanPkgNameditor.setValue(getSessionPkgName(seamProjectName));

    if ("".equals(entityBeanPkgNameditor.getValueAsString()))
      entityBeanPkgNameditor.setValue(getEntityPkgName(seamProjectName));

    if ("".equals(testsPkgNameditor.getValueAsString()))
      testsPkgNameditor.setValue(getTestPkgName(seamProjectName));

    if (!isWebProjectWizard()) {
      if ("".equals(ejbProjectNameditor.getValueAsString()))
        ejbProjectNameditor.setValue(getEJBProjectName(seamProjectName));

      if ("".equals(earProjectNameditor.getValueAsString()))
        earProjectNameditor.setValue(getEARProjectName(seamProjectName));
    }

    if ("".equals(testProjectNameditor.getValueAsString()))
      testProjectNameditor.setValue(getTestProjectName(seamProjectName));
  }
  public void createDatabaseGoupControl() {
    // disposeControls(jBossHibernateDbTypeEditor);
    disposeControls(connProfileSelEditor);
    disposeControls(dbSchemaName);
    disposeControls(dbCatalogName);
    disposeControls(dbTablesExists);
    disposeControls(recreateTablesOnDeploy);
    if (!needToShowConnectionProfile) {
      // jBossHibernateDbTypeEditor = null;
      connProfileSelEditor = null;
      dbSchemaName = null;
      dbCatalogName = null;
    } else {
      /*jBossHibernateDbTypeEditor = IFieldEditorFactory.INSTANCE
      .createComboEditor(ISeamFacetDataModelProperties.DB_TYPE,
      		SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_DATABASE_TYPE,
      		Arrays.asList(HIBERNATE_HELPER.getDialectNames()),
      		getDefaultDbType(), false);*/
      connProfileSelEditor =
          SeamWizardFactory.createConnectionProfileSelectionFieldEditor(
              getConnectionProfileDefaultValue(),
              new IValidator() {
                public Map<String, IStatus> validate(Object value, Object context) {
                  SeamInstallWizardPage.this.validate();
                  return SeamValidatorFactory.NO_ERRORS;
                }
              });
      dbSchemaName =
          IFieldEditorFactory.INSTANCE.createTextEditor(
              ISeamFacetDataModelProperties.DB_DEFAULT_SCHEMA_NAME,
              SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_DATABASE_SCHEMA_NAME,
              ""); //$NON-NLS-1$
      dbCatalogName =
          IFieldEditorFactory.INSTANCE.createTextEditor(
              ISeamFacetDataModelProperties.DB_DEFAULT_CATALOG_NAME,
              SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_DATABASE_CATALOG_NAME,
              ""); //$NON-NLS-1$

      jBossHibernateDbTypeEditor.addPropertyChangeListener(
          new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
              SeamInstallWizardPage.this.model.setProperty(
                  ISeamFacetDataModelProperties.HIBERNATE_DIALECT,
                  HIBERNATE_HELPER.getDialectClass(evt.getNewValue().toString()));
            }
          });
      // registerEditor(jBossHibernateDbTypeEditor, databaseGroup, 4);
      registerEditor(connProfileSelEditor, databaseGroup, 4);
      registerEditor(dbSchemaName, databaseGroup, 4);
      registerEditor(dbCatalogName, databaseGroup, 4);
    }
    dbTablesExists =
        IFieldEditorFactory.INSTANCE.createCheckboxEditor(
            ISeamFacetDataModelProperties.DB_ALREADY_EXISTS,
            SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_DB_TABLES_ALREADY_EXISTS,
            false);
    recreateTablesOnDeploy =
        IFieldEditorFactory.INSTANCE.createCheckboxEditor(
            ISeamFacetDataModelProperties.RECREATE_TABLES_AND_DATA_ON_DEPLOY,
            SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_RECREATE_DATABASE_TABLES_AND_DATA_ON_DEPLOY,
            false);
    registerEditor(dbTablesExists, databaseGroup, 4);
    registerEditor(recreateTablesOnDeploy, databaseGroup, 4);
    databaseGroup.getParent().layout(true);
  }
  /** Creates Seam Facet Wizard Page contents */
  public void createControl(Composite parent) {
    sync = new DataModelSynchronizer(model);
    jBossSeamHomeEditor =
        SeamWizardFactory.createSeamRuntimeSelectionFieldEditor(
            new SeamVersion[0],
            SeamFacetInstallDataModelProvider.getSeamRuntimeDefaultValue(model),
            new NewSeamRuntimeAction());

    initializeDialogUnits(parent);

    Composite root = new Composite(parent, SWT.NONE);
    GridData gd = new GridData();

    gd.horizontalSpan = 1;
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;

    GridLayout gridLayout = new GridLayout(1, false);
    root.setLayout(gridLayout);
    Group generalGroup = new Group(root, SWT.NONE);
    generalGroup.setLayoutData(gd);
    generalGroup.setText(SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_GENERAL);
    gridLayout = new GridLayout(3, false);

    generalGroup.setLayout(gridLayout);
    registerEditor(jBossSeamHomeEditor, generalGroup, 3);
    jBossSeamHomeEditor.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent arg0) {
            Boolean testProject = canTestProjectBeCreated();
            createTestProjectCheckboxeditor.setValue(testProject);
            createTestProjectCheckboxeditor.setEnabled(testProject);
          }
        });

    Object deployAs = getDeployAsDefaultValue();
    jBossAsDeployAsEditor.setValue(deployAs);

    registerEditor(jBossAsDeployAsEditor, generalGroup, 3);
    registerEditor(ejbProjectNameditor, generalGroup, 3);
    ejbProjectNameditor.setEnabled(deployAs.equals(ISeamFacetDataModelProperties.DEPLOY_AS_EAR));
    registerEditor(earProjectNameditor, generalGroup, 3);
    earProjectNameditor.setEnabled(deployAs.equals(ISeamFacetDataModelProperties.DEPLOY_AS_EAR));

    List<String> providers = new ArrayList<String>();
    providers.add(SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_COPY_LIBRARIES);
    providers.add(SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_CONFIGURE_LATER);

    libraryListEditor =
        IFieldEditorFactory.INSTANCE.createComboEditor(
            ISeamFacetDataModelProperties.SEAM_LIBRARY_PROVIDER,
            SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_LIBRARIES,
            providers,
            providers.get(0));

    registerEditor(libraryListEditor, generalGroup, 3);

    jBossAsDeployAsEditor.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent arg0) {
            Boolean value =
                jBossAsDeployAsEditor.getValue() == ISeamFacetDataModelProperties.DEPLOY_AS_EAR;
            if (!isWebProjectWizard()) {
              ejbProjectNameditor.setEnabled(value.booleanValue());
              earProjectNameditor.setEnabled(value.booleanValue());
            }
          }
        });

    gd = new GridData();
    gd.horizontalSpan = 1;
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;

    databaseGroup = new Group(root, SWT.NONE);
    databaseGroup.setLayoutData(gd);
    databaseGroup.setText(SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_DATABASE);
    gridLayout = new GridLayout(4, false);
    databaseGroup.setLayout(gridLayout);

    jBossHibernateDbTypeEditor =
        IFieldEditorFactory.INSTANCE.createComboEditor(
            ISeamFacetDataModelProperties.DB_TYPE,
            SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_DATABASE_TYPE,
            Arrays.asList(HIBERNATE_HELPER.getDialectNames()),
            getDefaultDbType(),
            false);
    registerEditor(jBossHibernateDbTypeEditor, databaseGroup, 4);

    createDatabaseGoupControl();

    Group generationGroup = new Group(root, SWT.NONE);
    gd = new GridData();
    gd.horizontalSpan = 1;
    gd.horizontalAlignment = GridData.FILL;
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = false;

    generationGroup.setLayoutData(gd);
    generationGroup.setText(SeamCoreMessages.SEAM_INSTALL_WIZARD_PAGE_CODE_GENERATION);
    gridLayout = new GridLayout(3, false);
    generationGroup.setLayout(gridLayout);
    registerEditor(sessionBeanPkgNameditor, generationGroup, 3);
    registerEditor(entityBeanPkgNameditor, generationGroup, 3);

    registerEditor(createTestProjectCheckboxeditor, generationGroup, 3);
    createTestProjectCheckboxeditor.addPropertyChangeListener(
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent arg0) {
            Boolean value = (Boolean) createTestProjectCheckboxeditor.getValue();
            testsPkgNameditor.setEnabled(value.booleanValue());
            testProjectNameditor.setEnabled(value.booleanValue());
          }
        });

    registerEditor(testProjectNameditor, generationGroup, 3);
    registerEditor(testsPkgNameditor, generationGroup, 3);

    if (!isSeamProjectWizard()) {
      createTestProjectCheckboxeditor.setValue(false);
      createTestProjectCheckboxeditor.setEnabled(false);
      testProjectNameditor.setEnabled(false);
      testsPkgNameditor.setEnabled(false);
      if (!isWebProjectWizard()) {
        libraryListEditor.setValue(providers.get(1));
        libraryListEditor.setEnabled(false);
      }
    }
    if (isWebProjectWizard()) {
      ejbProjectNameditor.setValue("");
      ejbProjectNameditor.setEnabled(false);
      earProjectNameditor.setValue("");
      earProjectNameditor.setEnabled(false);
    }

    setControl(root);

    if (validatorDelegate == null) {
      validatorDelegate = new DataModelValidatorDelegate(this.model, this);
      validatorDelegate.addValidatorForProperty(
          jBossSeamHomeEditor.getName(), SeamValidatorFactory.SEAM_RUNTIME_NAME_VALIDATOR);
      validatorDelegate.addValidatorForProperty(
          connProfileSelEditor.getName(), SeamValidatorFactory.CONNECTION_PROFILE_VALIDATOR);
      validatorDelegate.addValidatorForProperty(
          testsPkgNameditor.getName(),
          new PackageNameValidator(testsPkgNameditor.getName(), "tests")); // $NON-NLS-1$
      validatorDelegate.addValidatorForProperty(
          entityBeanPkgNameditor.getName(),
          new PackageNameValidator(
              entityBeanPkgNameditor.getName(), "entity beans")); // $NON-NLS-1$
      validatorDelegate.addValidatorForProperty(
          sessionBeanPkgNameditor.getName(),
          new PackageNameValidator(
              sessionBeanPkgNameditor.getName(), "session beans")); // $NON-NLS-1$
      if (isSeamProjectWizard()) {
        validatorDelegate.addValidatorForProperty(
            IFacetDataModelProperties.FACET_PROJECT_NAME,
            new ProjectNamesDuplicationValidator(IFacetDataModelProperties.FACET_PROJECT_NAME));
      }
      validatorDelegate.addValidatorForProperty(
          ISeamFacetDataModelProperties.JBOSS_AS_DEPLOY_AS,
          getDeploymentTypeValidator(getWizard()));

      validatorDelegate.addValidatorForProperty(
          ISeamFacetDataModelProperties.SEAM_EAR_PROJECT,
          new ProjectNamesDuplicationValidator(ISeamFacetDataModelProperties.SEAM_EAR_PROJECT));
      validatorDelegate.addValidatorForProperty(
          ISeamFacetDataModelProperties.SEAM_EJB_PROJECT,
          new ProjectNamesDuplicationValidator(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT));
      validatorDelegate.addValidatorForProperty(
          ISeamFacetDataModelProperties.SEAM_TEST_PROJECT,
          new ProjectNamesDuplicationValidator(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT));
    }

    Dialog.applyDialogFont(parent);
    initDefaultWizardProperties();
    Object parentDm = model.getProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM);
    if (parentDm != null) {
      ((IDataModel) parentDm).addListener(this);
    }
  }
 /**
  * Registers editor in data synchronizer and put SWT controls for it at wizard page.
  *
  * @param editor
  * @param parent
  * @param columns
  */
 protected void registerEditor(IFieldEditor editor, Composite parent, int columns) {
   sync.register(editor);
   editor.doFillIntoGrid(parent);
 }
 /*
  * test method
  */
 public String getTestsPkgName() {
   return testsPkgNameditor.getValueAsString();
 }
 /*
  * test method
  */
 public String getEntityBeanPkgName() {
   return entityBeanPkgNameditor.getValueAsString();
 }
 /*
  * test method
  */
 public String getSessionBeanPkgName() {
   return sessionBeanPkgNameditor.getValueAsString();
 }