use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class HSearchConsoleConfigurationPreferencesTest method testGetHSearchVersion.
@Test
public void testGetHSearchVersion() {
ConsoleConfigurationPreferences prefs = new StandAloneConsoleConfigurationPreferences("my-console-config", "4.3") {
};
ConsoleConfiguration consoleConfiguration = new ConsoleConfiguration(prefs);
KnownConfigurations.getInstance().addConfiguration(consoleConfiguration, false);
assertEquals(HSearchConsoleConfigurationPreferences.getHSearchVersion("my-console-config"), "5.3");
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class HibernateSearchEnabledPropertyTesterTest method allMustContainHibernateSearchLib.
@Test
public void allMustContainHibernateSearchLib() throws MalformedURLException {
ConsoleConfiguration consoleConfiguration1 = mock(ConsoleConfiguration.class);
ConsoleConfiguration consoleConfiguration2 = mock(ConsoleConfiguration.class);
ConsoleConfigurationPreferences prefs1 = mock(ConsoleConfigurationPreferences.class);
ConsoleConfigurationPreferences prefs2 = mock(ConsoleConfigurationPreferences.class);
when(consoleConfiguration1.getPreferences()).thenReturn(prefs1);
when(consoleConfiguration2.getPreferences()).thenReturn(prefs2);
when(prefs1.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "hibernate-search-orm-version") });
when(prefs1.getCustomClassPathURLS()).thenReturn(new URL[] { new URL("file", "", "something"), new URL("file", "", "dont-we-need") });
TreePath treePath = new TreePath(new Object[] { consoleConfiguration1, consoleConfiguration2 });
ITreeSelection receiver = new TreeSelection(treePath);
HibernateSearchEnabledPropertyTester tester = new HibernateSearchEnabledPropertyTester();
assertFalse(tester.test(receiver, "doesn't matter", null, null));
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class OneParentConfigPropertyTesterTest method testDifferentConfigs.
@Test
public void testDifferentConfigs() {
ConsoleConfiguration consoleConfiguration1 = mock(ConsoleConfiguration.class);
ConsoleConfiguration consoleConfiguration2 = mock(ConsoleConfiguration.class);
TreePath treePath1 = new TreePath(new Object[] { consoleConfiguration1 });
TreePath treePath2 = new TreePath(new Object[] { consoleConfiguration2 });
ITreeSelection receiver = new TreeSelection(new TreePath[] { treePath1, treePath2 });
OneParentConfigPropertyTester propertyTester = new OneParentConfigPropertyTester();
assertFalse(propertyTester.test(receiver, "doesn't matter", null, null));
}
use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.
the class CodeGenerationLaunchDelegate method launch.
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor) throws CoreException {
Assert.isNotNull(configuration);
Assert.isNotNull(monitor);
ExporterAttributes attributes = new ExporterAttributes(configuration);
ConsoleConfiguration cc = KnownConfigurations.getInstance().find(attributes.getConsoleConfigurationName());
ConsoleExtension consoleExtension = cc.getHibernateExtension().getConsoleExtension();
Map<String, File[]> generatedFiles = consoleExtension.launchExporters(configuration, mode, launch, monitor);
// code formatting needs to happen *after* refresh to make sure eclipse will format the uptodate files!
if (generatedFiles != null) {
formatGeneratedCode(monitor, generatedFiles);
}
/* The code is moved to consoleExtension and delegated method is called instead.
List<ExporterFactory> exporterFactories = attributes.getExporterFactories();
for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext();) {
ExporterFactory exFactory = iter.next();
if (!exFactory.isEnabled(configuration)) {
iter.remove();
}
}
if (attributes.isUseExternalProcess()) {
// create temporary build.xml and then erase it after code generation complete
String fileName = null;
try {
fileName = getPath2GenBuildXml().toString();
createBuildXmlFile(configuration, fileName);
} catch (UnsupportedEncodingException e) {
throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
} catch (IOException e) {
throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
}
configuration = updateLaunchConfig(configuration);
super.launch(configuration, mode, launch, monitor);
//
final Properties props = new Properties();
props.put(CodeGenerationStrings.EJB3, "" + attributes.isEJB3Enabled()); //$NON-NLS-1$
props.put(CodeGenerationStrings.JDK5, "" + attributes.isJDK5Enabled()); //$NON-NLS-1$
Set<String> outputDirs = new HashSet<String>();
for (Iterator<ExporterFactory> iter = exporterFactories.iterator(); iter.hasNext();) {
ExporterFactory exFactory = iter.next();
exFactory.collectOutputDirectories(attributes.getOutputPath(),
props, outputDirs);
}
//
final IProcess[] processes = launch.getProcesses();
// codegen listener to erase build.xml file after codegen process complete
CodeGenerationProcessListener refresher = new CodeGenerationProcessListener(
processes[0], fileName, outputDirs);
refresher.startBackgroundRefresh();
return;
}
try {
Set<String> outputDirectories = new HashSet<String>();
ExporterFactory[] exporters = exporterFactories.toArray( new ExporterFactory[exporterFactories.size()] );
ArtifactCollector collector = runExporters(attributes, exporters, outputDirectories, monitor);
for (String path : outputDirectories) {
CodeGenerationUtils.refreshOutputDir(path);
}
RefreshTab.refreshResources(configuration, monitor);
// code formatting needs to happen *after* refresh to make sure eclipse will format the uptodate files!
if(collector!=null) {
formatGeneratedCode( monitor, collector );
}
} catch(Exception e) {
throw new CoreException(HibernateConsolePlugin.throwableToStatus(e, 666));
} catch(NoClassDefFoundError e) {
throw new CoreException(HibernateConsolePlugin.throwableToStatus(new HibernateConsoleRuntimeException(HibernateConsoleMessages.CodeGenerationLaunchDelegate_received_noclassdeffounderror,e), 666));
} finally {
monitor.done();
}*/
}
use of org.hibernate.console.ConsoleConfiguration 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);
}
Aggregations