Search in sources :

Example 11 with KnownConfigurations

use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.

the class KnownConfigurationsTest method testKnownConfigurations.

@Test
public void testKnownConfigurations() {
    KnownConfigurations knownConfigurations = KnownConfigurations.getInstance();
    ConsoleConfiguration[] configurations = knownConfigurations.getConfigurations();
    Assert.assertEquals(0, configurations.length);
    CCListener listener = new CCListener();
    try {
        knownConfigurations.addConsoleConfigurationListener(listener);
        Assert.assertEquals(0, listener.added.size());
        ConsoleConfigurationPreferences preferences = new ConsoleConfigurationPreferences() {

            public void setName(String name) {
            }

            public void readStateFrom(Element element) {
            }

            public void writeStateTo(Element node) {
            }

            public File getPropertyFile() {
                return null;
            }

            public File getConfigXMLFile() {
                return null;
            }

            public Properties getProperties() {
                return null;
            }

            public File[] getMappingFiles() {
                return null;
            }

            public URL[] getCustomClassPathURLS() {
                return null;
            }

            public String getName() {
                return TestConsoleMessages.KnownConfigurationsTest_fake_prefs;
            }

            public String getEntityResolverName() {
                return null;
            }

            public ConfigurationMode getConfigurationMode() {
                return null;
            }

            public String getNamingStrategy() {
                return null;
            }

            public String getPersistenceUnitName() {
                return null;
            }

            public String getConnectionProfileName() {
                return null;
            }

            public String getDialectName() {
                return null;
            }

            public String getHibernateVersion() {
                return null;
            }
        };
        ConsoleConfigurationPreferences preferences2 = new ConsoleConfigurationPreferences() {

            String name = TestConsoleMessages.KnownConfigurationsTest_new_test;

            public void setName(String name) {
                this.name = name;
            }

            public void readStateFrom(Element element) {
            }

            public void writeStateTo(Element node) {
            }

            public File getPropertyFile() {
                return null;
            }

            public File getConfigXMLFile() {
                return null;
            }

            public Properties getProperties() {
                return null;
            }

            public File[] getMappingFiles() {
                return null;
            }

            public URL[] getCustomClassPathURLS() {
                return null;
            }

            public String getName() {
                return name;
            }

            public String getEntityResolverName() {
                return null;
            }

            public ConfigurationMode getConfigurationMode() {
                return null;
            }

            public String getNamingStrategy() {
                return null;
            }

            public String getPersistenceUnitName() {
                return null;
            }

            public String getConnectionProfileName() {
                return null;
            }

            public String getDialectName() {
                return null;
            }

            public String getHibernateVersion() {
                return null;
            }
        };
        ConsoleConfiguration configuration = new ConsoleConfiguration(preferences);
        ConsoleConfiguration configuration2 = new ConsoleConfiguration(preferences2);
        knownConfigurations.addConfiguration(configuration, false);
        knownConfigurations.addConfiguration(configuration2, false);
        configurations = knownConfigurations.getConfigurations();
        Assert.assertEquals(2, configurations.length);
        Assert.assertEquals(listener.added.size(), 0);
        knownConfigurations.addConfiguration(configuration, true);
        knownConfigurations.addConfiguration(configuration2, true);
        configurations = knownConfigurations.getConfigurations();
        Assert.assertEquals(2, configurations.length);
        Assert.assertEquals(listener.added.size(), 2);
        knownConfigurations.removeConfiguration(configuration, false);
        knownConfigurations.removeConfiguration(configuration2, false);
        configurations = knownConfigurations.getConfigurations();
        Assert.assertEquals(0, configurations.length);
        Assert.assertEquals(listener.added.size(), 0);
    } finally {
        KnownConfigurations.getInstance().removeConfigurationListener(listener);
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) ConsoleConfigurationPreferences(org.hibernate.console.preferences.ConsoleConfigurationPreferences) Element(org.w3c.dom.Element) KnownConfigurations(org.hibernate.console.KnownConfigurations) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 12 with KnownConfigurations

use of org.hibernate.console.KnownConfigurations in project jbosstools-hibernate by jbosstools.

the class KnownConfigurationsProvider method inputChanged.

public void inputChanged(Viewer v, Object oldInput, Object newInput) {
    super.inputChanged(v, oldInput, newInput);
    tv = (TreeViewer) v;
    if (oldInput != null && oldInput instanceof KnownConfigurations) {
        KnownConfigurations old = (KnownConfigurations) oldInput;
        if (old != null) {
            old.removeConfigurationListener(this);
        }
    }
    if (newInput != null && newInput instanceof KnownConfigurations) {
        KnownConfigurations newz = (KnownConfigurations) newInput;
        if (newz != null) {
            newz.addConsoleConfigurationListener(this);
        }
    }
}
Also used : KnownConfigurations(org.hibernate.console.KnownConfigurations)

Aggregations

KnownConfigurations (org.hibernate.console.KnownConfigurations)12 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)11 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)2 File (java.io.File)1 URL (java.net.URL)1 CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)1 ILaunchConfigurationListener (org.eclipse.debug.core.ILaunchConfigurationListener)1 ILaunchManager (org.eclipse.debug.core.ILaunchManager)1 PerformRefactoringOperation (org.eclipse.ltk.core.refactoring.PerformRefactoringOperation)1 ProcessorBasedRefactoring (org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring)1 Shell (org.eclipse.swt.widgets.Shell)1 KnownConfigurationsAdapter (org.hibernate.console.KnownConfigurationsAdapter)1 ConsoleConfigurationRenameProcessor (org.hibernate.eclipse.launch.core.refactoring.ConsoleConfigurationRenameProcessor)1 Test (org.junit.Test)1 Element (org.w3c.dom.Element)1