use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.
the class HibernateConsolePlugin method listenForConfigurations.
private void listenForConfigurations() {
final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
kcl = new KnownConfigurationsAdapter() {
/**
* @param root
* @param forUpdate - shows whether physical removal necessary
*/
public void configurationRemoved(ConsoleConfiguration root, boolean forUpdate) {
if (!forUpdate) {
try {
removeConfiguration(root.getName());
} catch (CoreException e) {
logErrorMessage(HibernateConsoleMessages.HibernateConsolePlugin_could_not_delete_launch_config_for + root.getName(), e);
}
}
}
};
KnownConfigurations.getInstance().addConsoleConfigurationListener(kcl);
icl = new ILaunchConfigurationListener() {
boolean isConsoleConfiguration(ILaunchConfiguration configuration) {
try {
return configuration.getType().getIdentifier().equals(ICodeGenerationLaunchConstants.CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID);
} catch (CoreException e) {
// HibernateConsolePlugin.getDefault().log( e );
// ignore since it occurs on delete
}
return false;
}
public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
ConsoleConfiguration cfg = KnownConfigurations.getInstance().find(configuration.getName());
if (cfg != null) {
// file system removal have been made already.
KnownConfigurations.getInstance().removeConfiguration(cfg, true);
}
}
public void launchConfigurationChanged(ILaunchConfiguration configuration) {
if (configuration.isWorkingCopy() || isTemporary(configuration)) {
return;
}
if (isConsoleConfiguration(configuration)) {
KnownConfigurations instance = KnownConfigurations.getInstance();
ConsoleConfiguration oldcfg = instance.find(configuration.getName());
if (oldcfg != null) {
// reset it no matter what.
oldcfg.reset();
} else {
// A new one!
ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
instance.addConfiguration(new ConsoleConfiguration(adapter), true);
}
}
}
private ConsoleConfigurationPreferences buildConfigurationPreferences(ILaunchConfiguration configuration) {
return new EclipseLaunchConsoleConfigurationPreferences(configuration);
}
public void launchConfigurationAdded(ILaunchConfiguration configuration) {
if (isConsoleConfiguration(configuration)) {
ILaunchConfiguration movedFrom = launchManager.getMovedFrom(configuration);
if (movedFrom != null && isConsoleConfiguration(movedFrom)) {
KnownConfigurations instance = KnownConfigurations.getInstance();
ConsoleConfiguration oldcfg = instance.find(movedFrom.getName());
if (oldcfg != null) {
// call this before we remove old configuration
refactor(movedFrom, configuration);
// reset it no matter what.
oldcfg.reset();
instance.removeConfiguration(oldcfg, false);
}
}
KnownConfigurations instance = KnownConfigurations.getInstance();
ConsoleConfigurationPreferences adapter = buildConfigurationPreferences(configuration);
boolean temporary = isTemporary(configuration);
if (!temporary) {
instance.addConfiguration(new ConsoleConfiguration(adapter), true);
}
}
}
private void refactor(ILaunchConfiguration oldConfiguration, ILaunchConfiguration newConfiguration) {
if (!oldConfiguration.getName().equals(newConfiguration.getName())) {
// only rename of console configuration refactoring is supported.
ConsoleConfigurationRenameProcessor proc = new ConsoleConfigurationRenameProcessor(oldConfiguration, newConfiguration.getName());
// Refactor for rename
PerformRefactoringOperation refOperation = new PerformRefactoringOperation(new ProcessorBasedRefactoring(proc), CheckConditionsOperation.ALL_CONDITIONS);
try {
ResourcesPlugin.getWorkspace().run(refOperation, null);
} catch (OperationCanceledException oce) {
throw new OperationCanceledException();
} catch (CoreException ce) {
HibernateConsolePlugin.openError(new Shell(), HibernateConsoleMessages.EditConsoleConfiguration_rename_refactoring_error_totle, ce.getLocalizedMessage(), ce, HibernateConsolePlugin.PERFORM_SYNC_EXEC);
}
}
}
private boolean isTemporary(ILaunchConfiguration configuration) {
boolean temporary = true;
try {
temporary = configuration.getAttribute(AddConfigurationAction.TEMPORARY_CONFIG_FLAG, false);
} catch (CoreException e) {
HibernateConsolePlugin.getDefault().showError(getShell(), HibernateConsoleMessages.HibernateConsolePlugin_problem_to_get_flag, e);
}
return temporary;
}
};
launchManager.addLaunchConfigurationListener(icl);
}
use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.
the class ElementsFactory method getConsoleConfig.
public ConsoleConfiguration getConsoleConfig() {
final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
return consoleConfig;
}
use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.
the class OrmDiagram method getConsoleConfig.
public ConsoleConfiguration getConsoleConfig() {
final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
return consoleConfig;
}
use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.
the class Shape method getConsoleConfig.
public ConsoleConfiguration getConsoleConfig() {
final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
ConsoleConfiguration consoleConfig = knownConfigurations.find(consoleConfigName);
return consoleConfig;
}
use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.
the class ConsoleConfigUtils method deleteConsoleConfig.
/**
* Delete console configuration with given name.
* @param name
*/
public static void deleteConsoleConfig(String name) {
final KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
final ConsoleConfiguration consoleConfig = knownConfigurations.find(name);
if (consoleConfig != null) {
consoleConfig.reset();
}
knownConfigurations.removeConfiguration(consoleConfig, false);
}
Aggregations