Search in sources :

Example 1 with IStringButtonAdapter

use of org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter in project jbosstools-hibernate by jbosstools.

the class GenerateInitWizardPage method createDBGroup.

/**
 * @param container
 * @param colCount
 */
private void createDBGroup(Composite container, int numColumns) {
    dbGroup = new Group(container, SWT.FILL);
    dbGroup.setLayout(new FillLayout());
    GridLayout layout = new GridLayout();
    dbGroup.setLayout(layout);
    layout.numColumns = numColumns;
    layout.verticalSpacing = 10;
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns;
    dbGroup.setLayoutData(gd);
    dbGroup.setText(Messages.GenerateInitWizardPage_databaseSettings);
    // ****************************connection profile*****************
    connectionProfileName = new ComboDialogField(SWT.READ_ONLY);
    connectionProfileName.setLabelText(Messages.GenerateInitWizardPage_databaseSettings_connection);
    connectionProfileName.setItems(dtpConnectionProfileNames());
    String connectionName = getProjectConnectionProfileName();
    if (!isEmpty(connectionName)) {
        connectionProfileName.selectItem(connectionName);
    }
    connectionProfileName.doFillIntoGrid(dbGroup, numColumns);
    connectionProfileName.setDialogFieldListener(fieldlistener);
    connectionProfileName.setEnabled(!useConsoleConfiguration.getSelection());
    // ****************************dialect*****************
    dialectName = new ComboDialogField(SWT.NONE);
    dialectName.setLabelText(HibernateConsoleMessages.NewConfigurationWizardPage_database_dialect);
    dialectName.setItems(getDialectNames());
    dialectName.selectItem(0);
    dialectName.doFillIntoGrid(dbGroup, numColumns);
    dialectName.setEnabled(false);
    dialectName.setDialogFieldListener(fieldlistener);
    // ****************************schema*****************
    schemaName = new StringButtonDialogField(new IStringButtonAdapter() {

        public void changeControlPressed(DialogField field) {
        // TODO Auto-generated method stub
        }
    });
    schemaName.setLabelText(Messages.GenerateInitWizardPage_databaseShema);
    schemaName.setButtonLabel(Messages.GenerateInitWizardPage_refresh);
    Control[] controls = schemaName.doFillIntoGrid(dbGroup, numColumns);
    // Hack to tell the text field to stretch!
    ((GridData) controls[1].getLayoutData()).grabExcessHorizontalSpace = true;
    schemaName.setEnabled(!useConsoleConfiguration.getSelection());
}
Also used : Group(org.eclipse.swt.widgets.Group) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) GridData(org.eclipse.swt.layout.GridData) ComboDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField) StringButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField) FillLayout(org.eclipse.swt.layout.FillLayout) ComboDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField) StringButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField) DialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) IStringButtonAdapter(org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter)

Example 2 with IStringButtonAdapter

use of org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter in project jbosstools-hibernate by jbosstools.

the class CodeGenerationSettingsTab method createControl.

public void createControl(Composite parent) {
    // initializeDialogUnits(parent);
    final ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    Composite container = new Composite(sc, SWT.NULL);
    sc.setContent(container);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 4;
    layout.verticalSpacing = 10;
    IDialogFieldListener fieldlistener = new IDialogFieldListener() {

        public void dialogFieldChanged(DialogField field) {
            dialogChanged();
        }
    };
    useExternalProcess = new SelectionButtonDialogField(SWT.CHECK);
    useExternalProcess.setDialogFieldListener(fieldlistener);
    useExternalProcess.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_use_generation_in_external_process);
    consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
    consoleConfigurationName.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_console_configuration);
    ConsoleConfiguration[] cfg = LaunchHelper.findFilteredSortedConsoleConfigs();
    String[] names = new String[cfg.length + 1];
    names[0] = NULL_CONFIG;
    for (int i = 0; i < cfg.length; i++) {
        ConsoleConfiguration configuration = cfg[i];
        names[i + 1] = configuration.getName();
    }
    consoleConfigurationName.setItems(names);
    consoleConfigurationName.setDialogFieldListener(fieldlistener);
    outputdir = new StringButtonDialogField(new IStringButtonAdapter() {

        public void changeControlPressed(DialogField field) {
            // IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(),  PathHelper.pathOrNull(outputdir.getText()), new IPath[0], "Select output directory", "Choose directory in which the generated files will be stored", new String[] {"cfg.xml"}, false, true, false);
            IPath[] paths = DialogSelectionHelper.chooseFolderEntries(getShell(), PathHelper.pathOrNull(outputdir.getText()), HibernateConsoleMessages.CodeGenerationSettingsTab_select_output_dir, HibernateConsoleMessages.CodeGenerationSettingsTab_choose_dir_for_generated_files, false);
            if (paths != null && paths.length == 1) {
                outputdir.setText(((paths[0]).toOSString()));
            }
        }
    });
    outputdir.setDialogFieldListener(fieldlistener);
    outputdir.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_output_dir);
    outputdir.setButtonLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_browse);
    templatedir = new DirectoryBrowseField(null, null, HibernateConsoleMessages.CodeGenerationSettingsTab_select_template_dir, HibernateConsoleMessages.CodeGenerationSettingsTab_choose_dir_custom_templates);
    templatedir.setDialogFieldListener(fieldlistener);
    templatedir.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_template_directory);
    templatedir.setFilesystemBrowseLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_filesystem);
    templatedir.setWorkspaceBrowseLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_workspace);
    packageName = new StringDialogField();
    packageName.setDialogFieldListener(fieldlistener);
    packageName.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_package);
    reverseEngineeringStrategy = new StringButtonDialogField(new IStringButtonAdapter() {

        public void changeControlPressed(DialogField field) {
            IService service = getService();
            String string = DialogSelectionHelper.chooseImplementation(service.getReverseEngineeringStrategyClassName(), reverseEngineeringStrategy.getText(), HibernateConsoleMessages.CodeGenerationSettingsTab_choose_reverse_engineering_strategy, getShell());
            if (string != null) {
                reverseEngineeringStrategy.setText(string);
            }
        }
    });
    reverseEngineeringStrategy.setDialogFieldListener(fieldlistener);
    reverseEngineeringStrategy.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_reveng_strategy);
    reverseEngineeringStrategy.setButtonLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_browse);
    reverseEngineeringSettings = new StringButtonDialogField(new IStringButtonAdapter() {

        public void changeControlPressed(DialogField field) {
            int defaultChoice = 0;
            IPath reverseEngineeringSettingsFile = getReverseEngineeringSettingsFile();
            if (reverseEngineeringSettingsFile == null) {
                defaultChoice = 0;
            } else {
                defaultChoice = 1;
            }
            MessageDialog dialog = new MessageDialog(getShell(), HibernateConsoleMessages.CodeGenerationSettingsTab_setup_reverse_engineering, null, HibernateConsoleMessages.CodeGenerationSettingsTab_do_you_want_create_reveng_xml, MessageDialog.QUESTION, new String[] { HibernateConsoleMessages.CodeGenerationSettingsTab_create_new, HibernateConsoleMessages.CodeGenerationSettingsTab_use_existing, IDialogConstants.CANCEL_LABEL }, defaultChoice);
            int answer = dialog.open();
            if (answer == 0) {
                // create new
                NewReverseEngineeringFileWizard wizard = new NewReverseEngineeringFileWizard();
                wizard.init(PlatformUI.getWorkbench(), selection);
                wizard.setSelectConfiguration(getConfigurationName());
                IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                WizardDialog wdialog = new WizardDialog(win.getShell(), wizard);
                // This opens a dialog
                wdialog.open();
                IPath createdFilePath = wizard.getCreatedFilePath();
                if (createdFilePath != null) {
                    reverseEngineeringSettings.setText(createdFilePath.toOSString());
                }
            } else if (answer == 1) {
                // use existing
                IPath[] paths = DialogSelectionHelper.chooseFileEntries(getShell(), reverseEngineeringSettingsFile, new IPath[0], HibernateConsoleMessages.CodeGenerationSettingsTab_select_reverse_engineering_settings_file, HibernateConsoleMessages.CodeGenerationSettingsTab_choose_file_read_reverse_settings, new String[] { HibernateConsoleMessages.CodeGenerationSettingsTab_reveng_xml_1 }, false, false, true);
                if (paths != null && paths.length == 1) {
                    reverseEngineeringSettings.setText(((paths[0]).toOSString()));
                }
            }
        }
    });
    reverseEngineeringSettings.setDialogFieldListener(fieldlistener);
    reverseEngineeringSettings.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_reveng_xml_2);
    reverseEngineeringSettings.setButtonLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_setup);
    reverseengineer = new SelectionButtonDialogField(SWT.CHECK);
    reverseengineer.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_reverse_engineer_from_jdbc_connection);
    reverseengineer.setDialogFieldListener(fieldlistener);
    useOwnTemplates = new SelectionButtonDialogField(SWT.CHECK);
    useOwnTemplates.setDialogFieldListener(fieldlistener);
    useOwnTemplates.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_use_custom_templates);
    preferRawCompositeIds = new SelectionButtonDialogField(SWT.CHECK);
    preferRawCompositeIds.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_generate_basic_typed_composite_ids);
    preferRawCompositeIds.setSelection(true);
    preferRawCompositeIds.setDialogFieldListener(fieldlistener);
    autoManyToMany = new SelectionButtonDialogField(SWT.CHECK);
    autoManyToMany.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_detect_many_to_many_tables);
    autoManyToMany.setSelection(true);
    autoManyToMany.setDialogFieldListener(fieldlistener);
    autoOneToOne = new SelectionButtonDialogField(SWT.CHECK);
    autoOneToOne.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_detect_one_to_one_associations);
    autoOneToOne.setSelection(true);
    autoOneToOne.setDialogFieldListener(fieldlistener);
    autoVersioning = new SelectionButtonDialogField(SWT.CHECK);
    autoVersioning.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_detect_optimistic_lock_columns);
    autoVersioning.setSelection(true);
    autoVersioning.setDialogFieldListener(fieldlistener);
    useOwnTemplates.attachDialogField(templatedir);
    reverseengineer.attachDialogFields(new DialogField[] { packageName, preferRawCompositeIds, reverseEngineeringSettings, reverseEngineeringStrategy, autoManyToMany, autoOneToOne, autoVersioning });
    // do not show the option cause: JBIDE-8072
    // useExternalProcess.doFillIntoGrid(container, 4);
    useExternalProcess.setSelection(false);
    consoleConfigurationName.doFillIntoGrid(container, 4);
    Control[] controls = outputdir.doFillIntoGrid(container, 4);
    // Hack to tell the text field to stretch!
    ((GridData) controls[1].getLayoutData()).grabExcessHorizontalSpace = true;
    reverseengineer.doFillIntoGrid(container, 4);
    packageName.doFillIntoGrid(container, 4);
    reverseEngineeringSettings.doFillIntoGrid(container, 4);
    reverseEngineeringStrategy.doFillIntoGrid(container, 4);
    fillLabel(container);
    preferRawCompositeIds.doFillIntoGrid(container, 3);
    fillLabel(container);
    autoVersioning.doFillIntoGrid(container, 3);
    fillLabel(container);
    autoManyToMany.doFillIntoGrid(container, 3);
    fillLabel(container);
    autoOneToOne.doFillIntoGrid(container, 3);
    useOwnTemplates.doFillIntoGrid(container, 4);
    controls = templatedir.doFillIntoGrid(container, 4);
    // Hack to tell the text field to stretch!
    ((GridData) controls[1].getLayoutData()).grabExcessHorizontalSpace = true;
    sc.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    dialogChanged();
    setControl(sc);
}
Also used : StringButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField) IStringButtonAdapter(org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) ComboDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) ComboDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField) StringDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField) StringButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField) SelectionButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField) DialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) SelectionButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField) IService(org.jboss.tools.hibernate.runtime.spi.IService) IDialogFieldListener(org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IPath(org.eclipse.core.runtime.IPath) StringDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField) NewReverseEngineeringFileWizard(org.hibernate.eclipse.console.wizards.NewReverseEngineeringFileWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 3 with IStringButtonAdapter

use of org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter in project jbosstools-hibernate by jbosstools.

the class GenerateInitWizardPage method createControl.

/* (non-Javadoc)
	 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
	 */
public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = numColumns;
    layout.verticalSpacing = 10;
    outputdir = new StringButtonDialogField(new IStringButtonAdapter() {

        public void changeControlPressed(DialogField field) {
            IPath[] paths = DialogSelectionHelper.chooseFolderEntries(getShell(), PathHelper.pathOrNull(outputdir.getText()), HibernateConsoleMessages.CodeGenerationSettingsTab_select_output_dir, HibernateConsoleMessages.CodeGenerationSettingsTab_choose_dir_for_generated_files, false);
            if (paths != null && paths.length == 1) {
                outputdir.setText(((paths[0]).toOSString()));
            }
        }
    });
    outputdir.setText(getDefaultOutput());
    outputdir.setDialogFieldListener(fieldlistener);
    outputdir.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_output_dir);
    outputdir.setButtonLabel(HibernateConsoleMessages.CodeGenerationSettingsTab_browse);
    Control[] controls = outputdir.doFillIntoGrid(container, numColumns);
    // Hack to tell the text field to stretch!
    ((GridData) controls[1].getLayoutData()).grabExcessHorizontalSpace = true;
    setPageComplete(!StringHelper.isEmpty(getOutputDir()));
    createChildControls(container);
    useConsoleConfiguration = new Button(container, SWT.CHECK);
    useConsoleConfiguration.setText(Messages.GenerateInitWizardPage_use_console_configuration);
    useConsoleConfiguration.setSelection(true);
    useConsoleConfiguration.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            widgetSelected(e);
        }

        public void widgetSelected(SelectionEvent e) {
            consoleConfigurationName.setEnabled(useConsoleConfiguration.getSelection());
            hibernateVersion.setEnabled(!useConsoleConfiguration.getSelection());
            connectionProfileName.setEnabled(!useConsoleConfiguration.getSelection());
            schemaName.setEnabled(!useConsoleConfiguration.getSelection());
            dialectName.setEnabled(!useConsoleConfiguration.getSelection());
            dialogChanged();
        }
    });
    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalSpan = numColumns;
    useConsoleConfiguration.setLayoutData(gd);
    consoleConfigurationName = new ComboDialogField(SWT.READ_ONLY);
    consoleConfigurationName.setLabelText(HibernateConsoleMessages.CodeGenerationSettingsTab_console_configuration);
    ConsoleConfiguration[] cfg = LaunchHelper.findFilteredSortedConsoleConfigs();
    String[] names = new String[cfg.length];
    for (int i = 0; i < cfg.length; i++) {
        ConsoleConfiguration configuration = cfg[i];
        names[i] = configuration.getName();
    }
    consoleConfigurationName.setItems(names);
    consoleConfigurationName.setText(jpaProject.getDefaultConsoleConfigurationName());
    consoleConfigurationName.setDialogFieldListener(fieldlistener);
    consoleConfigurationName.doFillIntoGrid(container, numColumns);
    hibernateVersion = new ComboDialogField(SWT.READ_ONLY);
    hibernateVersion.setLabelText(HibernateConsoleMessages.ConsoleConfigurationMainTab_0);
    hibernateVersion.setItems(ServiceLookup.getVersions());
    hibernateVersion.selectItem(0);
    hibernateVersion.setDialogFieldListener(fieldlistener);
    hibernateVersion.doFillIntoGrid(container, numColumns);
    hibernateVersion.setEnabled(false);
    createDBGroup(container, numColumns);
    setControl(container);
    if (StringHelper.isEmpty(consoleConfigurationName.getText())) {
        setPageComplete(false);
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) StringButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField) IStringButtonAdapter(org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter) GridLayout(org.eclipse.swt.layout.GridLayout) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) GridData(org.eclipse.swt.layout.GridData) ComboDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField) ComboDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField) StringButtonDialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField) DialogField(org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ComboDialogField (org.eclipse.jdt.internal.ui.wizards.dialogfields.ComboDialogField)3 DialogField (org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField)3 IStringButtonAdapter (org.eclipse.jdt.internal.ui.wizards.dialogfields.IStringButtonAdapter)3 StringButtonDialogField (org.eclipse.jdt.internal.ui.wizards.dialogfields.StringButtonDialogField)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Control (org.eclipse.swt.widgets.Control)3 IPath (org.eclipse.core.runtime.IPath)2 GridData (org.eclipse.swt.layout.GridData)2 Composite (org.eclipse.swt.widgets.Composite)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 IDialogFieldListener (org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener)1 SelectionButtonDialogField (org.eclipse.jdt.internal.ui.wizards.dialogfields.SelectionButtonDialogField)1 StringDialogField (org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Button (org.eclipse.swt.widgets.Button)1