diff options
39 files changed, 0 insertions, 3623 deletions
diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.classpath b/jpa/tests/org.eclipse.jpt.db.tests/.classpath deleted file mode 100644 index 52f3036201..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/.classpath +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> - <accessrules> - <accessrule kind="accessible" pattern="org/eclipse/jpt/db/**"/> - <accessrule kind="accessible" pattern="org/eclipse/jpt/utility/**"/> - </accessrules> - </classpathentry> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.cvsignore b/jpa/tests/org.eclipse.jpt.db.tests/.cvsignore deleted file mode 100644 index ba077a4031..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -bin diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.project b/jpa/tests/org.eclipse.jpt.db.tests/.project deleted file mode 100644 index f5b0127a1e..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jpt.db.tests</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.core.resources.prefs b/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.core.resources.prefs deleted file mode 100644 index b23d0c7038..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/.settings/org.eclipse.core.resources.prefs +++ /dev/null @@ -1,3 +0,0 @@ -#Tue Jan 15 11:11:11 EST 2008 -eclipse.preferences.version=1 -encoding/<project>=ISO-8859-1 diff --git a/jpa/tests/org.eclipse.jpt.db.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.db.tests/META-INF/MANIFEST.MF deleted file mode 100644 index de87ac8d1b..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,18 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.db.tests -Bundle-Version: 1.0.0.qualifier -Bundle-Activator: org.eclipse.jpt.db.tests.internal.JptDbTestsPlugin -Bundle-Localization: plugin -Eclipse-LazyStart: false -Require-Bundle: org.eclipse.core.runtime, - org.junit, - org.eclipse.datatools.connectivity, - org.eclipse.datatools.connectivity.db.generic, - org.eclipse.jpt.utility, - org.eclipse.jpt.db -Export-Package: org.eclipse.jpt.db.tests.internal;x-internal:=true, - org.eclipse.jpt.db.tests.internal.platforms;x-internal:=true -Bundle-RequiredExecutionEnvironment: J2SE-1.5 diff --git a/jpa/tests/org.eclipse.jpt.db.tests/build.properties b/jpa/tests/org.eclipse.jpt.db.tests/build.properties deleted file mode 100644 index cd0d010fd1..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/build.properties +++ /dev/null @@ -1,15 +0,0 @@ -############################################################################### -# Copyright (c) 2007 Oracle. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# Oracle - initial API and implementation -############################################################################### -source.. = src/ -output.. = bin/ -bin.includes = .,\ - META-INF/,\ - plugin.properties diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/derby101.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/derby101.properties deleted file mode 100644 index 1d97add8dd..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/derby101.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Platform Property names & Default -# -# profileName - jpatest -# profileDescription - JDBC Profile for JPA Testing -# userName - jpatest -# userPassword - (empty) -# databasedriverJarList - (mandatory) -# databaseName - testdb -# databaseUrl - (mandatory) -# Driver class name - org.apache.derby.jdbc.EmbeddedDriver -# -profileName = derby101 -profileDescription = Derby Embedded JDBC Profile for Testing -# set user name -userName = -userPassword = -# set path to Derby driver here (example: databasedriverJarList = c:/derbydb/lib/derby.jar ) -databasedriverJarList = -databaseName = testdb -# set database URL here (example: databaseUrl = jdbc:derby:c:/derbydb/testdb;create=true ) -databaseUrl = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/mysql41.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/mysql41.properties deleted file mode 100644 index 4ac94784bb..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/mysql41.properties +++ /dev/null @@ -1,22 +0,0 @@ -# Platform Property names & Default -# -# profileName - jpatest -# profileDescription - JDBC Profile for JPA Testing -# userName - jpatest -# userPassword - (empty) -# databasedriverJarList - (mandatory) -# databaseName - testdb -# databaseUrl - (mandatory) -# -# Driver class (jconn3.jar) - com.mysql.jdbc.Driver -# -profileName = mysq41 -profileDescription = MySql 4.1.16 JDBC Profile for Testing -# set user name -userName = -userPassword = -# set path to Derby driver here (example: databasedriverJarList = C:/jlib/mysql-connector-java-3.1.7-bin.jar ) -databasedriverJarList = -databaseName = testdb -# set database URL here (example: databaseUrl = jdbc:sybase:Tds:localhost:5000/testdb ) -databaseUrl = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10g.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10g.properties deleted file mode 100644 index 603e56d7db..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10g.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Platform Property names & Default -# -# profileName - jpatest -# profileDescription - JDBC Profile for JPA Testing -# userName - jpatest -# userPassword - (empty) -# databasedriverJarList - jar list separate by comma (mandatory) -# databaseName - testdb -# databaseUrl - (mandatory) -# Driver: oracle.jdbc.OracleDriver -# -profileName = Oracle10g_10_1_0_4 -profileDescription = Oracle10g (10.1.0.4) Thin JDBC Profile for Testing -userName = -userPassword = -# set path to Oracle driver here (example: databasedriverJarList = c:/oracle/jdbc/lib/ojdbc14.jar ) -databasedriverJarList = -databaseName = -# set database URL here (example: databaseUrl = jdbc:oracle:thin:@localhost:1521:testdb ) -databaseUrl = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10gXE.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10gXE.properties deleted file mode 100644 index 8d72946e2a..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle10gXE.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Platform Property names & Default -# -# profileName - jpatest -# profileDescription - JDBC Profile for JPA Testing -# userName - jpatest -# userPassword - (empty) -# databasedriverJarList - jar list separate by comma (mandatory) -# databaseName - testdb -# databaseUrl - (mandatory) -# Driver: oracle.jdbc.OracleDriver -# -profileName = oracleXE10g -profileDescription = Oracle10g XE Release 2 (10.2) Thin JDBC Profile for Testing -userName = scott -userPassword = tiger -# set path to Oracle driver here (example: databasedriverJarList = c:/oracle/jdbc/lib/ojdbc14.jar ) -databasedriverJarList = -databaseName = XE -# set database URL here (example: databaseUrl = jdbc:oracle:thin:@localhost:1521:XE ) -databaseUrl = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle9i.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/oracle9i.properties deleted file mode 100644 index 8357e15c58..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/oracle9i.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Platform Property names & Default -# -# profileName - jpatest -# profileDescription - JDBC Profile for JPA Testing -# userName - jpatest -# userPassword - (empty) -# databasedriverJarList - jar list separate by comma (mandatory) -# databaseName - testdb -# databaseUrl - (mandatory) -# Driver: oracle.jdbc.OracleDriver -# -profileName = oracle9i -profileDescription = Oracle Thin JDBC Profile for Testing -userName = -userPassword = -# set path to Oracle driver here (example: databasedriverJarList = c:/oracle/jdbc/lib/ojdbc14.jar ) -databasedriverJarList = -databaseName = testdb -# set database URL here (example: databaseUrl = jdbc:oracle:thin:@server:1521:testdb ) -databaseUrl = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/postgresql824.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/postgresql824.properties deleted file mode 100644 index f529359523..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/postgresql824.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Platform Property names & Default -# -# profileName - jpatest -# profileDescription - JDBC Profile for JPA Testing -# userName - jpatest -# userPassword - (empty) -# databasedriverJarList - (mandatory) -# databaseName - testdb -# databaseUrl - (mandatory) -# Driver class (postgresql-8.2-505.jdbc2.jar) - org.postgresql.Driver -# -profileName = postgresql -profileDescription = PostgreSQL 8.2.4 JDBC Profile for Testing -# set user name -userName = -userPassword = -# set path to Derby driver here (example: databasedriverJarList = c:/jlib/postgresql-8.2-505.jdbc2.jar) -databasedriverJarList = -databaseName = postgres -# set database URL here (example: databaseUrl = jdbc:postgresql:postgres ) -databaseUrl = jdbc:postgresql:postgres diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/sqlserver2005.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/sqlserver2005.properties deleted file mode 100644 index 8451351e83..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/sqlserver2005.properties +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################### -# Copyright (c) 2007 Oracle. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# Oracle - initial API and implementation -############################################################################### -# Platform Property names & Default -# -# profileName - jpatest -# profileDescription - JDBC Profile for JPA Testing -# userName - jpatest -# userPassword - (empty) -# databasedriverJarList - (mandatory) -# databaseName - testdb -# databaseUrl - (mandatory) -# -profileName = sqlserver2005 -profileDescription = MS SQL Server 2005 JDBC Profile for Testing -# set user name -userName = -userPassword = -# set path to Derby driver here (example: databasedriverJarList = c:/sqlserver/lib/sqljdbc.jar ) -databasedriverJarList = -databaseName = testdb -# set database URL here (example: databaseUrl = jdbc:sqlserver://localhost:1433;databaseName=testdb ) -databaseUrl = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/config/sybase12.properties b/jpa/tests/org.eclipse.jpt.db.tests/config/sybase12.properties deleted file mode 100644 index 34aab2556b..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/config/sybase12.properties +++ /dev/null @@ -1,21 +0,0 @@ -# Platform Property names & Default -# -# profileName - jpatest -# profileDescription - JDBC Profile for JPA Testing -# userName - jpatest -# userPassword - (empty) -# databasedriverJarList - (mandatory) -# databaseName - testdb -# databaseUrl - (mandatory) -# Driver class (jconn3.jar) - com.sybase.jdbc3.jdbc.SybDriver -# -profileName = jconnect6 -profileDescription = Sybase 12.x jConnect JDBC Profile for Testing -# set user name -userName = -userPassword = -# set path to Derby driver here (example: databasedriverJarList = c:/sybase/lib/jconn3.jar ) -databasedriverJarList = -databaseName = testdb -# set database URL here (example: databaseUrl = jdbc:sybase:Tds:localhost:5000/testdb ) -databaseUrl = diff --git a/jpa/tests/org.eclipse.jpt.db.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.db.tests/plugin.properties deleted file mode 100644 index b04fe27976..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/plugin.properties +++ /dev/null @@ -1,25 +0,0 @@ -############################################################################### -# Copyright (c) 2007 Oracle. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# Oracle - initial API and implementation -############################################################################### -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName = JPA DB Tests -providerName = Eclipse.org - diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTests.java deleted file mode 100644 index ecb2b84188..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTests.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal; - -import org.eclipse.jpt.db.tests.internal.platforms.AllPlatformTests; - -import junit.framework.Test; -import junit.framework.TestSuite; -import junit.swingui.TestRunner; - -/** - * JptDbTests - */ -public class JptDbTests { - - public static void main( String[] args) { - TestRunner.main( new String[] { "-c", JptDbTests.class.getName()}); - } - - public static Test suite() { - TestSuite suite = new TestSuite(JptDbTests.class.getPackage().getName()); - - suite.addTest( AllPlatformTests.suite()); - - return suite; - } - - private JptDbTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTestsPlugin.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTestsPlugin.java deleted file mode 100644 index a5fe382da0..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/JptDbTestsPlugin.java +++ /dev/null @@ -1,56 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the terms of - * the Eclipse Public License v1.0, which accompanies this distribution and is available at - * http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal; - -import org.eclipse.core.runtime.Plugin; -import org.osgi.framework.BundleContext; - -/** - * JptDbTestsPlugin - */ -public class JptDbTestsPlugin extends Plugin { - - // The shared instance - private static JptDbTestsPlugin plugin; - - public static final String BUNDLE_ID = "org.eclipse.jpt.db.tests"; //$NON-NLS-1$ - - /** - * Returns the shared instance - */ - public static JptDbTestsPlugin getDefault() { - return plugin; - } - - /** - * The constructor - */ - public JptDbTestsPlugin() { - super(); - plugin = this; - } - - /** - * This method is called upon plug-in activation - */ - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - } - - /** - * This method is called when the plug-in is stopped - */ - @Override - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/AllPlatformTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/AllPlatformTests.java deleted file mode 100644 index d76ac11cdb..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/AllPlatformTests.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - -import junit.framework.Test; -import junit.framework.TestSuite; -import junit.swingui.TestRunner; - -/** - * AllPlatformTests - */ -public class AllPlatformTests { - - public static void main( String[] args) { - TestRunner.main( new String[] { "-c", AllPlatformTests.class.getName()}); - } - - public static Test suite() { - TestSuite suite = new TestSuite(AllPlatformTests.class.getPackage().getName()); - -// TODO - Uncomment the platform to test. -// suite.addTestSuite(Derby101Tests.class); -// suite.addTestSuite(Oracle9iTests.class); -// suite.addTestSuite(Oracle10gTests.class); -// suite.addTestSuite(Oracle10gXETests.class); -// suite.addTestSuite(SQLServer2005Tests.class); -// suite.addTestSuite(MySQL41Tests.class); -// suite.addTestSuite(PostgreSQL824Tests.class); -// suite.addTestSuite(Sybase12Tests.class); - - return suite; - } - - private AllPlatformTests() { - super(); - throw new UnsupportedOperationException(); - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java deleted file mode 100644 index 11622031bb..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/DTPPlatformTests.java +++ /dev/null @@ -1,417 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.NoSuchElementException; -import java.util.Properties; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.datatools.connectivity.ConnectionProfileException; -import org.eclipse.datatools.connectivity.IConnectionProfile; -import org.eclipse.datatools.connectivity.ProfileManager; -import org.eclipse.datatools.connectivity.db.generic.IDBDriverDefinitionConstants; -import org.eclipse.datatools.connectivity.drivers.IDriverMgmtConstants; -import org.eclipse.datatools.connectivity.drivers.IPropertySet; -import org.eclipse.datatools.connectivity.drivers.PropertySetImpl; -import org.eclipse.datatools.connectivity.drivers.XMLFileManager; -import org.eclipse.datatools.connectivity.internal.ConnectivityPlugin; -import org.eclipse.jpt.db.internal.ConnectionProfile; -import org.eclipse.jpt.db.internal.ConnectionProfileRepository; -import org.eclipse.jpt.db.internal.DTPConnectionProfileWrapper; -import org.eclipse.jpt.db.internal.Database; -import org.eclipse.jpt.db.internal.Schema; -import org.eclipse.jpt.db.internal.Table; -import org.eclipse.jpt.db.tests.internal.JptDbTestsPlugin; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; - -/** - * Base class for all supported DTP platform. - */ -public abstract class DTPPlatformTests extends TestCase { - - protected ConnectionProfileRepository connectionRepository; - - private Properties platformProperties; - private String currentDbVendor; - private String currentDbVersion; - - private static final String PLATFORM_CONFIG_DIRECTORY = "config"; //$NON-NLS-1$ - - private static final String PROFILE_NAME_PROPERTY = "profileName"; //$NON-NLS-1$ - private static final String PROFILE_DESCRIPTION_PROPERTY = "profileDescription"; //$NON-NLS-1$ - private static final String USER_NAME_PROPERTY = "userName"; //$NON-NLS-1$ - private static final String USER_PASSWORD_PROPERTY = "userPassword"; //$NON-NLS-1$ - private static final String DB_DRIVER_JAR_PROPERTY = "databasedriverJarList"; //$NON-NLS-1$ - private static final String DB_NAME_PROPERTY = "databaseName"; //$NON-NLS-1$ - private static final String DB_URL_PROPERTY = "databaseUrl"; //$NON-NLS-1$ - - private static final String PROFILE_NAME_DEFAULT = "jpatest"; //$NON-NLS-1$ - private static final String PROFILE_DESCRIPTION_DEFAULT = "JDBC Profile for JPA Testing"; //$NON-NLS-1$ - private static final String USER_NAME_DEFAULT = "userName"; //$NON-NLS-1$ - private static final String USER_PASSWORD_DEFAULT = ""; //$NON-NLS-1$ - private static final String DB_NAME_DEFAULT = "testdb"; //$NON-NLS-1$ - - private static final String MISSING_PROPERTY_MESSAGE = "Enter missing property in platform config file (config/database.properties)"; - - public DTPPlatformTests( String name) { - super( name); - - this.connectionRepository = ConnectionProfileRepository.instance(); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.connectionRepository.start(); - - if( this.platformIsNew()) { - this.loadPlatformProperties(); - - this.buildDriverDefinitionFile( IDriverMgmtConstants.DRIVER_FILE); - this.buildConnectionProfile( this.profileName()); - this.currentDbVendor = this.databaseVendor(); - this.currentDbVersion = this.databaseVersion(); - } - this.verifyProfileNamed( this.profileName()); - } - - @Override - protected void tearDown() throws Exception { - - this.connectionRepository.stop(); - super.tearDown(); - } - - // ********** tests ********** - - public void testConnection() throws Exception { - - this.connect(); - - this.verifyDatabaseVersionNumber(); - this.verifyDatabaseContent(); - - this.disconnect(); - } - - public void testGetProfiles() { - // Getting the profile directly from DTP ProfileManager - IConnectionProfile[] profiles = ProfileManager.getInstance().getProfiles(); - Assert.assertNotNull( profiles); - Assert.assertTrue( profiles.length > 0); - } - - public void testGetProfilesByProvider() { - // Get Profiles By ProviderID - IConnectionProfile[] profiles = ProfileManager.getInstance().getProfileByProviderID( this.getProfile().getProviderId()); - Assert.assertNotNull( profiles); - Assert.assertTrue( profiles.length > 0); - } - - public void testGetProfileByName() { - // Get Profile By Name - IConnectionProfile dtpProfile = this.getDTPProfile(); - Assert.assertNotNull( dtpProfile); - Assert.assertTrue( dtpProfile.getName().equals( this.profileName())); - } - - public void testGetProfileByInstanceId() { - // Get Profile By InstanceID - IConnectionProfile dtpProfile = ProfileManager.getInstance().getProfileByInstanceID( this.getProfile().getInstanceId()); - Assert.assertNotNull( dtpProfile); - Assert.assertTrue( dtpProfile.getName().equals( this.profileName())); - } - - public void testWorkingOffline() { - - if( this.getProfile().supportsWorkOfflineMode()) { - - if( ! this.getProfile().canWorkOffline()) { - this.connect(); - this.saveWorkOfflineData(); - this.disconnect(); - - Assert.assertTrue( this.getProfile().canWorkOffline()); - } - this.workOffline(); - - Assert.assertTrue( this.getProfile().isConnected()); - Assert.assertTrue( this.getProfile().isWorkingOffline()); - - this.disconnect(); - } - } - - // ********** internal tests ********** - - private void verifyDatabaseVersionNumber() { - Database database = this.getProfile().getDatabase(); - Assert.assertNotNull( database); - - String actualVersionNumber = database.getVersion(); - String expectedVersionNumber = this.databaseVersion(); - String errorMessage = "Expected version number: " + expectedVersionNumber + " but the actual version number was: " + actualVersionNumber; - assertTrue( errorMessage, actualVersionNumber.indexOf( expectedVersionNumber) != -1); - - String actualVendor = database.getVendor(); - String expectedVendor = this.databaseVendor(); - errorMessage = "Expected vendor: " + expectedVendor + " but the actual vendor was: " + actualVendor; - assertEquals( errorMessage, actualVendor, expectedVendor); - } - - private void verifyDatabaseContent() { - Database database = this.getProfile().getDatabase(); - Assert.assertTrue( database.schemataSize() > 0); - - Schema schema = database.schemaNamed( this.getProfile().getUserName()); - if( schema != null) { - Assert.assertTrue( schema.sequencesSize() >= 0); - - Object[] tableNames = CollectionTools.array( schema.tableNames()); - if( tableNames.length >= 1) { - Table table = schema.tableNamed(( String)tableNames[ 0]); - Assert.assertTrue( table.columnsSize() >= 0); - Assert.assertTrue( table.foreignKeyColumnsSize() >= 0); - Assert.assertTrue( table.foreignKeysSize() >= 0); - Assert.assertTrue( table.primaryKeyColumnsSize() >= 0); - } - } - } - - private void verifyProfileNamed( String profileName) { - - ConnectionProfile profile = this.getProfileNamed( profileName); - Assert.assertTrue( "ConnectionProfile not found", profileName.equals( profile.getName())); - } - - // ***** Platform specific behavior ***** - - protected abstract String databaseVendor(); - protected abstract String databaseVersion(); - - protected abstract String driverName(); - protected abstract String driverDefinitionType(); - protected abstract String driverDefinitionId(); - protected abstract String driverClass(); - - protected abstract String getConfigName(); - - // ***** Behavior ***** - - protected void connect() { - - this.getProfile().connect(); - Assert.assertTrue( "Could not connect.", this.getProfile().isConnected()); - Assert.assertFalse( "Connection corrupted.", this.getProfile().isWorkingOffline()); - } - - protected void disconnect() { - - this.getProfile().disconnect(); - Assert.assertFalse( "Disconnect failed.", this.getProfile().isConnected()); - } - - private void workOffline() { - IStatus status = this.getProfile().workOffline(); - - Assert.assertTrue( "Could not work offline.", status.isOK()); - } - - private void saveWorkOfflineData() { - IStatus status = this.getProfile().saveWorkOfflineData(); - - Assert.assertTrue( "Could not save offline data.", status.isOK()); - } - - // ********** queries ********** - - protected Schema getSchemaNamed( String schemaName) { - - return this.getProfile().getDatabase().schemaNamed( schemaName); - } - - protected Collection<Table> getTables() { - - Schema schema = this.getSchemaNamed( this.getProfile().getUserName()); - if( schema == null) { - return new ArrayList<Table>(); - } - return CollectionTools.collection( schema.tables()); - } - - protected Table getTableNamed( String tableName) { - - Schema schema = this.getSchemaNamed( this.getProfile().getUserName()); - Assert.assertNotNull( schema); - - return schema.tableNamed( tableName); - } - - protected String providerId() { - return DTPConnectionProfileWrapper.CONNECTION_PROFILE_TYPE; - } - - protected String passwordIsSaved() { - return "true"; - } - - - protected IConnectionProfile getDTPProfile() { - return ProfileManager.getInstance().getProfileByName( this.profileName()); - } - - protected String profileName() { - return this.platformProperties.getProperty( PROFILE_NAME_PROPERTY, PROFILE_NAME_DEFAULT); - } - - protected String profileDescription() { - return this.platformProperties.getProperty( PROFILE_DESCRIPTION_PROPERTY, PROFILE_DESCRIPTION_DEFAULT); - } - - protected String userName() { - return this.platformProperties.getProperty( USER_NAME_PROPERTY, USER_NAME_DEFAULT); - } - - protected String userPassword() { - return this.platformProperties.getProperty( USER_PASSWORD_PROPERTY, USER_PASSWORD_DEFAULT); - } - - protected String databaseName() { - return this.platformProperties.getProperty( DB_NAME_PROPERTY, DB_NAME_DEFAULT); - } - - protected String databasedriverJarList() { - String dbDriverJarList = this.platformProperties.getProperty( DB_DRIVER_JAR_PROPERTY); - if ( StringTools.stringIsEmpty( dbDriverJarList)) { - throw new NoSuchElementException( MISSING_PROPERTY_MESSAGE); - } - return dbDriverJarList; - } - - protected String databaseUrl() { - String dbUrl = this.platformProperties.getProperty( DB_URL_PROPERTY); - if ( StringTools.stringIsEmpty( dbUrl)) { - throw new NoSuchElementException( MISSING_PROPERTY_MESSAGE); - } - return dbUrl; - } - - protected ConnectionProfile getProfile() { - - return this.getProfileNamed( this.profileName()); - } - - protected ConnectionProfile getProfileNamed( String profileName) { - - return ConnectionProfileRepository.instance().profileNamed( profileName); - } - - private String getTestPluginBundleId() { - return JptDbTestsPlugin.BUNDLE_ID; - } - - private IPath getDriverDefinitionLocation() { - return ConnectivityPlugin.getDefault().getStateLocation(); - } - - private String getConfigPath() { - return this.getConfigDir() + "/" + this.getConfigName(); - } - - private String getConfigDir() { - return PLATFORM_CONFIG_DIRECTORY; - } - - private boolean platformIsNew() { - return( !this.databaseVendor().equals( this.currentDbVendor) || this.databaseVersion().equals( this.currentDbVersion)); - } - - private void loadPlatformProperties() throws IOException { - - if( this.platformProperties == null) { - URL configUrl = Platform.getBundle( this.getTestPluginBundleId()).getEntry( this.getConfigPath()); - - this.platformProperties = new Properties(); - this.platformProperties.load( configUrl.openStream()); - } - } - - private Properties buildDriverProperties() { - Properties driverProperties = new Properties(); - driverProperties.setProperty( DTPConnectionProfileWrapper.DRIVER_DEFINITION_TYPE_PROP_ID, this.driverDefinitionType()); - driverProperties.setProperty( DTPConnectionProfileWrapper.DRIVER_JAR_LIST_PROP_ID, this.databasedriverJarList()); - driverProperties.setProperty( IDBDriverDefinitionConstants.USERNAME_PROP_ID, this.userName()); - driverProperties.setProperty( IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, this.driverClass()); - driverProperties.setProperty( IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID, this.databaseName()); - driverProperties.setProperty( IDBDriverDefinitionConstants.PASSWORD_PROP_ID, this.userPassword()); - driverProperties.setProperty( IDBDriverDefinitionConstants.URL_PROP_ID, this.databaseUrl()); - driverProperties.setProperty( IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, this.databaseVendor()); - driverProperties.setProperty( IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, this.databaseVersion()); - return driverProperties; - } - - private Properties buildBasicProperties() { - Properties basicProperties = new Properties(); - basicProperties.setProperty( IDBDriverDefinitionConstants.DATABASE_NAME_PROP_ID, this.databaseName()); - basicProperties.setProperty( IDBDriverDefinitionConstants.USERNAME_PROP_ID, this.userName()); - basicProperties.setProperty( IDBDriverDefinitionConstants.PASSWORD_PROP_ID, this.userPassword()); - basicProperties.setProperty( DTPConnectionProfileWrapper.DRIVER_DEFINITION_PROP_ID, this.driverDefinitionId()); - - basicProperties.setProperty( IDBDriverDefinitionConstants.DRIVER_CLASS_PROP_ID, this.driverClass()); - basicProperties.setProperty( IDBDriverDefinitionConstants.URL_PROP_ID, this.databaseUrl()); - basicProperties.setProperty( IDBDriverDefinitionConstants.DATABASE_VENDOR_PROP_ID, this.databaseVendor()); - basicProperties.setProperty( IDBDriverDefinitionConstants.DATABASE_VERSION_PROP_ID, this.databaseVersion()); - - basicProperties.setProperty( DTPConnectionProfileWrapper.DATABASE_SAVE_PWD_PROP_ID, this.passwordIsSaved()); - return basicProperties; - } - - private void buildConnectionProfile( String profileName) throws ConnectionProfileException { - - ProfileManager profileManager = ProfileManager.getInstance(); - Assert.assertNotNull( profileManager); - - IConnectionProfile dtpProfile = this.getDTPProfile(); - if( dtpProfile == null) { - Properties basicProperties = buildBasicProperties(); - ProfileManager.getInstance().createProfile( profileName, this.profileDescription(), this.providerId(), basicProperties); - } - } - - private void buildDriverDefinitionFile( String driverFileName) throws CoreException { - - XMLFileManager.setStorageLocation( this.getDriverDefinitionLocation()); - XMLFileManager.setFileName( driverFileName); - IPropertySet[] propsets = new IPropertySet[ 1]; - String driverName = this.driverName(); - String driverId = this.driverDefinitionId(); - PropertySetImpl propertySet = new PropertySetImpl( driverName, driverId); - propertySet.setProperties( driverId, this.buildDriverProperties()); - propsets[ 0] = propertySet; - - XMLFileManager.saveNamedPropertySet( propsets); - - File driverDefinitioneFile = this.getDriverDefinitionLocation().append( driverFileName).toFile(); - Assert.assertTrue( driverDefinitioneFile.exists()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Derby101Tests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Derby101Tests.java deleted file mode 100644 index 2244b0e623..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Derby101Tests.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * Derby 10.1 Embedded Driver Test - */ -public class Derby101Tests extends DTPPlatformTests { - - public Derby101Tests( String name) { - super( name); - } - - @Override - protected String databaseVendor() { - return "Derby"; - } - - @Override - protected String databaseVersion() { - return "10.1"; - } - - @Override - protected String providerId() { - return "org.eclipse.datatools.connectivity.db.derby.embedded.connectionProfile"; - } - - @Override - protected String driverName() { - return "Derby Embedded JDBC Driver"; - } - - @Override - protected String driverDefinitionType() { - return "org.eclipse.datatools.connectivity.db.derby101.genericDriverTemplate"; - } - - @Override - protected String driverDefinitionId() { - return "DriverDefn.Derby Embedded JDBC Driver"; - } - - @Override - protected String driverClass() { - return "org.apache.derby.jdbc.EmbeddedDriver"; - } - - @Override - protected String getConfigName() { - return "derby101.properties"; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/MySQL41Tests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/MySQL41Tests.java deleted file mode 100644 index 37c190f113..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/MySQL41Tests.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * SQL Server 2005 Driver Test - */ -public class MySQL41Tests extends DTPPlatformTests { - - public MySQL41Tests( String name) { - super( name); - } - - @Override - protected String databaseVendor() { - return "MySql"; - } - - @Override - protected String databaseVersion() { - return "4.1"; - } - - @Override - protected String driverClass() { - return "com.mysql.jdbc.Driver"; - } - - @Override - protected String driverDefinitionId() { - return "DriverDefn.MySQL JDBC Driver"; - } - - @Override - protected String driverDefinitionType() { - return "org.eclipse.datatools.enablement.mysql.4_1.driverTemplate"; - } - - @Override - protected String driverName() { - return "MySQL JDBC Driver"; - } - - @Override - protected String getConfigName() { - return "mysql41.properties"; - } - -}
\ No newline at end of file diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gTests.java deleted file mode 100644 index 4fa85b4db8..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * Oracle 10g Thin Driver Test - */ -public class Oracle10gTests extends DTPPlatformTests { - - public Oracle10gTests( String name) { - super( name); - } - - @Override - protected String databaseVendor() { - return "Oracle"; - } - - @Override - protected String databaseVersion() { - return "10"; - } - - @Override - protected String driverClass() { - return "oracle.jdbc.OracleDriver"; - } - - @Override - protected String driverDefinitionId() { - return "DriverDefn.Oracle Thin Driver"; - } - - @Override - protected String driverDefinitionType() { - return "org.eclipse.datatools.enablement.oracle.10.driverTemplate"; - } - - @Override - protected String driverName() { - return "Oracle 10g Thin Driver"; - } - - @Override - protected String getConfigName() { - return "oracle10g.properties"; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gXETests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gXETests.java deleted file mode 100644 index 78e0548b1b..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle10gXETests.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * Oracle 10g Thin Driver Test - */ -public class Oracle10gXETests extends DTPPlatformTests { - - public Oracle10gXETests( String name) { - super( name); - } - - @Override - protected String databaseVendor() { - return "Oracle"; - } - - @Override - protected String databaseVersion() { - return "10"; - } - - @Override - protected String driverClass() { - return "oracle.jdbc.OracleDriver"; - } - - @Override - protected String driverDefinitionId() { - return "DriverDefn.Oracle Thin Driver"; - } - - @Override - protected String driverDefinitionType() { - return "org.eclipse.datatools.enablement.oracle.10.driverTemplate"; - } - - @Override - protected String driverName() { - return "Oracle 10g Thin Driver"; - } - - @Override - protected String getConfigName() { - return "oracle10gXE.properties"; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle9iTests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle9iTests.java deleted file mode 100644 index 8e1795dc24..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Oracle9iTests.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * Oracle 9i Thin Driver Test - */ -public class Oracle9iTests extends DTPPlatformTests { - - public Oracle9iTests( String name) { - super( name); - } - - @Override - protected String databaseVendor() { - return "Oracle"; - } - - @Override - protected String databaseVersion() { - return "9"; - } - - @Override - protected String driverClass() { - return "oracle.jdbc.OracleDriver"; - } - - @Override - protected String driverDefinitionId() { - return "DriverDefn.Oracle Thin Driver"; - } - - @Override - protected String driverDefinitionType() { - return "org.eclipse.datatools.enablement.oracle.9.driverTemplate"; - } - - @Override - protected String driverName() { - return "Oracle 9i Thin Driver"; - } - - @Override - protected String getConfigName() { - return "oracle9i.properties"; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/PostgreSQL824Tests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/PostgreSQL824Tests.java deleted file mode 100644 index 8e011ad987..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/PostgreSQL824Tests.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * Oracle 10g Thin Driver Test - */ -public class PostgreSQL824Tests extends DTPPlatformTests { - - public PostgreSQL824Tests( String name) { - super( name); - } - - @Override - protected String databaseVendor() { - return "postgres"; - } - - @Override - protected String databaseVersion() { - return "8.x"; - } - - @Override - protected String driverClass() { - return "org.postgresql.Driver"; - } - - @Override - protected String driverDefinitionId() { - return "DriverDefn.PostgreSQL JDBC Driver"; - } - - @Override - protected String driverDefinitionType() { - return "org.eclipse.datatools.enablement.postgresql.postgresqlDriverTemplate"; - } - - @Override - protected String driverName() { - return "PostgreSQL JDBC Driver"; - } - - @Override - protected String getConfigName() { - return "postgresql824.properties"; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SQLServer2005Tests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SQLServer2005Tests.java deleted file mode 100644 index 350d844d56..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/SQLServer2005Tests.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * SQL Server 2005 Driver Test - */ -public class SQLServer2005Tests extends DTPPlatformTests { - - public SQLServer2005Tests( String name) { - super( name); - } - - @Override - protected String databaseVendor() { - return "SQLServer"; - } - - @Override - protected String databaseVersion() { - return "2005"; - } - - @Override - protected String providerId() { - return "org.eclipse.datatools.connectivity.db.generic.connectionProfile"; - } - - @Override - protected String driverName() { - return "Microsoft SQL Server 2005 JDBC Driver"; - } - - @Override - protected String driverDefinitionType() { - return "org.eclipse.datatools.enablement.msft.sqlserver.2005.driverTemplate"; - } - - @Override - protected String driverDefinitionId() { - return "DriverDefn.Microsoft SQL Server 2005 JDBC Driver"; - } - - @Override - protected String driverClass() { - return "com.microsoft.sqlserver.jdbc.SQLServerDriver"; - } - - @Override - protected String getConfigName() { - return "sqlserver2005.properties"; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Sybase12Tests.java b/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Sybase12Tests.java deleted file mode 100644 index c6c7eb3e89..0000000000 --- a/jpa/tests/org.eclipse.jpt.db.tests/src/org/eclipse/jpt/db/tests/internal/platforms/Sybase12Tests.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.db.tests.internal.platforms; - - -/** - * Oracle 10g Thin Driver Test - */ -public class Sybase12Tests extends DTPPlatformTests { - - public Sybase12Tests( String name) { - super( name); - } - - @Override - protected String databaseVendor() { - return "Sybase"; - } - - @Override - protected String databaseVersion() { - return "12.x"; - } - - @Override - protected String driverClass() { - return "com.sybase.jdbc3.jdbc.SybDriver"; - } - - @Override - protected String driverDefinitionId() { - return "DriverDefn.Sybase JDBC Driver"; - } - - @Override - protected String driverDefinitionType() { - return "org.eclipse.datatools.enablement.sybase.ase.12_x.driverTemplate"; - } - - @Override - protected String driverName() { - return "Sybase JDBC Driver"; - } - - @Override - protected String getConfigName() { - return "sybase12.properties"; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/.classpath b/jpa/tests/org.eclipse.jpt.ui.tests/.classpath deleted file mode 100644 index 370877baf6..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/.classpath +++ /dev/null @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> - <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"> - <accessrules> - <accessrule kind="accessible" pattern="org/eclipse/jpt/ui/**"/> - <accessrule kind="accessible" pattern="org/eclipse/jpt/core/**"/> - <accessrule kind="accessible" pattern="org/eclipse/jpt/utility/**"/> - </accessrules> - </classpathentry> - <classpathentry kind="output" path="bin"/> -</classpath> diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/.project b/jpa/tests/org.eclipse.jpt.ui.tests/.project deleted file mode 100644 index 0240774761..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/.project +++ /dev/null @@ -1,28 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<projectDescription> - <name>org.eclipse.jpt.ui.tests</name> - <comment></comment> - <projects> - </projects> - <buildSpec> - <buildCommand> - <name>org.eclipse.jdt.core.javabuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.ManifestBuilder</name> - <arguments> - </arguments> - </buildCommand> - <buildCommand> - <name>org.eclipse.pde.SchemaBuilder</name> - <arguments> - </arguments> - </buildCommand> - </buildSpec> - <natures> - <nature>org.eclipse.pde.PluginNature</nature> - <nature>org.eclipse.jdt.core.javanature</nature> - </natures> -</projectDescription> diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF b/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF deleted file mode 100644 index 89e2edbab8..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/META-INF/MANIFEST.MF +++ /dev/null @@ -1,18 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: %pluginName -Bundle-Vendor: %providerName -Bundle-SymbolicName: org.eclipse.jpt.ui.tests -Bundle-Version: 1.0.0 -Require-Bundle: org.junit, - org.eclipse.core.runtime, - org.eclipse.jface, - org.eclipse.jpt.core.tests, - org.eclipse.jpt.core.tests.extension.resource, - org.eclipse.jpt.utility, - org.eclipse.jpt.core, - org.eclipse.jpt.ui -Eclipse-LazyStart: true -Export-Package: org.eclipse.jpt.ui.tests;x-internal:=true, - org.eclipse.jpt.ui.tests.internal.platform;x-internal:=true, - org.eclipse.jpt.ui.tests.internal.swt;x-internal:=true diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/build.properties b/jpa/tests/org.eclipse.jpt.ui.tests/build.properties deleted file mode 100644 index 34d2e4d2da..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/build.properties +++ /dev/null @@ -1,4 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/plugin.properties b/jpa/tests/org.eclipse.jpt.ui.tests/plugin.properties deleted file mode 100644 index ca8ab879ff..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/plugin.properties +++ /dev/null @@ -1,22 +0,0 @@ -############################################################################### -# Copyright (c) 2006, 2007 Oracle. All rights reserved. This -# program and the accompanying materials are made available under the terms of -# the Eclipse Public License v1.0 which accompanies this distribution, and is -# available at http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: Oracle. - initial API and implementation -############################################################################### -# ==================================================================== -# To code developer: -# Do NOT change the properties between this line and the -# "%%% END OF TRANSLATED PROPERTIES %%%" line. -# Make a new property name, append to the end of the file and change -# the code to use the new property. -# ==================================================================== - -# ==================================================================== -# %%% END OF TRANSLATED PROPERTIES %%% -# ==================================================================== - -pluginName=Java Persistence API UI Tests -providerName=Eclipse.org diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java deleted file mode 100644 index 98f849359c..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/JptUiTests.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006, 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.tests; - -import org.eclipse.jpt.ui.tests.internal.platform.JptUiPlatformTests; -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * Runs all JPT UI Tests - */ -public class JptUiTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptUiTests.class.getPackage().getName()); - suite.addTest(JptUiPlatformTests.suite()); - return suite; - } - - private JptUiTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java deleted file mode 100644 index f792c808be..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingLabelProviderUiTest.java +++ /dev/null @@ -1,590 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.tests.internal.jface; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ArrayContentProvider; -import org.eclipse.jface.viewers.BaseLabelProvider; -import org.eclipse.jface.viewers.ComboViewer; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.jface.AbstractItemLabelProvider; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.ui.internal.jface.IItemLabelProvider; -import org.eclipse.jpt.ui.internal.jface.IItemLabelProviderFactory; -import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProviderFactory; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.internal.model.value.ListValueModel; -import org.eclipse.jpt.utility.internal.model.value.NullListValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.StaticListValueModel; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - -public class DelegatingLabelProviderUiTest extends ApplicationWindow -{ - private TreeViewer tree; - - private WritablePropertyValueModel<Vehicle> selectedVehicle; - - - public static void main(String[] args) { - Window window = new DelegatingLabelProviderUiTest(args); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - - private DelegatingLabelProviderUiTest(String[] args) { - super(null); - this.selectedVehicle = new SimplePropertyValueModel<Vehicle>(); - } - - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(ClassTools.shortClassNameForObject(this)); - parent.setSize(400, 400); - parent.setLayout(new GridLayout()); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayoutData(new GridData(GridData.FILL_BOTH)); - mainPanel.setLayout(new GridLayout()); - buildTreePanel(mainPanel); - buildControlPanel(mainPanel); - return mainPanel; - } - - private void buildTreePanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayoutData(new GridData(GridData.FILL_BOTH)); - panel.setLayout(new GridLayout()); - - Label label = new Label(panel, SWT.NONE); - label.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false)); - label.setText("My Vehicles"); - - tree = new TreeViewer(panel, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - tree.getTree().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); - DelegatingContentAndLabelProvider contentAndLabelProvider = - new DelegatingTreeContentAndLabelProvider( - new VehicleContentProviderFactory(), - new VehicleLabelProviderFactory()); - tree.setContentProvider(contentAndLabelProvider); - tree.setLabelProvider(contentAndLabelProvider); - tree.setInput(new Root()); - tree.addSelectionChangedListener(buildTreeSelectionChangedListener()); - } - - private ISelectionChangedListener buildTreeSelectionChangedListener() { - return new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - selectedVehicle.setValue((Vehicle) ((IStructuredSelection) event.getSelection()).getFirstElement()); - } - }; - } - - private void buildControlPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - panel.setLayout(new GridLayout()); - buildUpperControlPanel(panel); - buildLowerControlPanel(panel); - } - - private void buildUpperControlPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - panel.setLayout(new GridLayout(2, true)); - buildVehicleCombo(panel); - buildColorCombo(panel); - } - - private void buildVehicleCombo(Composite parent) { - final ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY); - combo.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - combo.setContentProvider(new ArrayContentProvider()); - combo.setLabelProvider(new VehicleTypeLabelProvider()); - combo.setInput( - new VehicleType[] { - VehicleType.BICYCLE, VehicleType.CAR, - VehicleType.TRUCK, VehicleType.BOAT - }); - combo.getCombo().setEnabled(false); - combo.addSelectionChangedListener( - new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - selectedVehicle().setVehicleType((VehicleType) ((StructuredSelection) event.getSelection()).getFirstElement()); - } - }); - selectedVehicle.addPropertyChangeListener( - PropertyValueModel.VALUE, - new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - Vehicle vehicle = selectedVehicle(); - combo.getCombo().setEnabled(vehicle != null); - combo.setSelection(new StructuredSelection((vehicle == null) ? null : vehicle.vehicleType())); - } - }); - } - - private void buildColorCombo(Composite parent) { - final ComboViewer combo = new ComboViewer(parent, SWT.READ_ONLY); - combo.getCombo().setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - combo.setContentProvider(new ArrayContentProvider()); - combo.setLabelProvider(new ColorLabelProvider()); - combo.setInput(new Color[] {Color.RED, Color.BLUE, Color.YELLOW, Color.GREEN}); - combo.addSelectionChangedListener( - new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - selectedVehicle().setColor((Color) ((StructuredSelection) event.getSelection()).getFirstElement()); - } - }); - selectedVehicle.addPropertyChangeListener( - PropertyValueModel.VALUE, - new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - Vehicle vehicle = selectedVehicle(); - combo.getCombo().setEnabled(vehicle != null); - combo.setSelection(new StructuredSelection((vehicle == null) ? null : vehicle.color())); - } - }); - } - - private void buildLowerControlPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - panel.setLayout(new GridLayout(3, false)); - buildEffectsLabel(panel); - buildGreyedCheckBox(panel); - buildTranslucentCheckBox(panel); - buildActionPanel(panel); - } - - private void buildEffectsLabel(Composite parent) { - Label label = new Label(parent, SWT.LEFT); - label.setText("Color effects: "); - label.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false, 3, 1)); - } - - private void buildGreyedCheckBox(Composite parent) { - final Button button = new Button(parent, SWT.CHECK); - button.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false)); - button.setText("greyed"); - button.setEnabled(false); - button.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - selectedVehicle().setGreyed(button.getSelection()); - } - }); - selectedVehicle.addPropertyChangeListener( - PropertyValueModel.VALUE, - new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - Vehicle vehicle = selectedVehicle(); - button.setEnabled(vehicle != null); - button.setSelection(vehicle != null && vehicle.isGreyed()); - } - }); - } - - private void buildTranslucentCheckBox(Composite parent) { - final Button button = new Button(parent, SWT.CHECK); - button.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false)); - button.setText("translucent"); - button.setEnabled(false); - button.addSelectionListener( - new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - selectedVehicle().setTranslucent(button.getSelection()); - } - }); - selectedVehicle.addPropertyChangeListener( - PropertyValueModel.VALUE, - new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - Vehicle vehicle = selectedVehicle(); - button.setEnabled(vehicle != null); - button.setSelection(vehicle != null && vehicle.isTranslucent()); - } - }); - } - - private void buildActionPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayoutData(new GridData(GridData.END, GridData.FILL, false, false)); - panel.setLayout(new GridLayout()); - buildRefreshTreeACI().fill(panel); - } - - private ActionContributionItem buildRefreshTreeACI() { - Action action = new Action("Refresh tree", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - refreshTree(); - } - }; - action.setToolTipText("Refresh the tree's labels"); - return new ActionContributionItem(action); - } - - void refreshTree() { - tree.refresh(); - } - - private Vehicle selectedVehicle() { - return selectedVehicle.value(); - } - - - private static class VehicleTypeLabelProvider extends BaseLabelProvider - implements ILabelProvider - { - public Image getImage(Object element) { - return null; - } - - public String getText(Object element) { - return ((VehicleType) element).description(); - } - } - - - private static class ColorLabelProvider extends BaseLabelProvider - implements ILabelProvider - { - public Image getImage(Object element) { - return null; - } - - public String getText(Object element) { - return ((Color) element).description(); - } - } - - - private static class VehicleContentProviderFactory - implements ITreeItemContentProviderFactory - { - public ITreeItemContentProvider buildItemContentProvider(Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - if (item instanceof Root) { - return new RootContentProvider( - (Root) item, (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider); - } - return new VehicleContentProvider( - (Vehicle) item, (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider); - } - } - - - private static class RootContentProvider extends AbstractTreeItemContentProvider<Vehicle> - { - public RootContentProvider(Root item, DelegatingTreeContentAndLabelProvider contentAndLabelProvider) { - super(item, contentAndLabelProvider); - } - - @Override - public Object getParent() { - return null; - } - - @Override - protected ListValueModel<Vehicle> buildChildrenModel() { - return new StaticListValueModel<Vehicle>(CollectionTools.list(((Root) model()).vehicles())); - } - } - - @SuppressWarnings("unchecked") - private static class VehicleContentProvider extends AbstractTreeItemContentProvider - { - public VehicleContentProvider(Vehicle item, DelegatingTreeContentAndLabelProvider contentAndLabelProvider) { - super(item, contentAndLabelProvider); - } - - @Override - public Object getParent() { - return ((Vehicle) model()).parent(); - } - - @Override - protected ListValueModel buildChildrenModel() { - return new NullListValueModel(); - } - } - - - private static class VehicleLabelProviderFactory - implements IItemLabelProviderFactory - { - public IItemLabelProvider buildItemLabelProvider(Object element, DelegatingContentAndLabelProvider labelProvider) { - return new VehicleLabelProvider((Vehicle) element, labelProvider); - } - } - - - private static class VehicleLabelProvider extends AbstractItemLabelProvider - { - public VehicleLabelProvider(Vehicle vehicle, DelegatingContentAndLabelProvider labelProvider) { - super(vehicle, labelProvider); - } - - @Override - protected PropertyValueModel<String> buildTextModel() { - return new PropertyAspectAdapter<Vehicle, String>( - new StaticPropertyValueModel<Vehicle>((Vehicle) model()), - Vehicle.VEHICLE_TYPE_PROPERTY, Vehicle.COLOR_PROPERTY) { - @Override - protected String buildValue_() { - return subject.color().description() + ' ' + subject.vehicleType().description(); - } - }; - } - - @Override - protected PropertyValueModel<Image> buildImageModel() { - return new PropertyAspectAdapter<Vehicle, Image>( - new StaticPropertyValueModel<Vehicle>((Vehicle) model()), - Vehicle.COLOR_PROPERTY, Vehicle.GREYED_PROPERTY, Vehicle.TRANSLUCENT_PROPERTY) { - @Override - protected Image buildValue_() { - return subject.image(); - } - }; - } - } - - - private static abstract class TreeNode extends AbstractModel - { - private TreeNode parent; - - - public TreeNode(TreeNode parent) { - this.parent = parent; - } - - - public TreeNode parent() { - return parent; - } - } - - - private static class Root extends TreeNode - { - protected final Vehicle[] vehicles; - - - public Root() { - super(null); - vehicles = new Vehicle[] { - new Vehicle(this, VehicleType.BICYCLE, Color.BLUE), - new Vehicle(this, VehicleType.CAR, Color.YELLOW), - new Vehicle(this, VehicleType.TRUCK, Color.RED), - new Vehicle(this, VehicleType.BOAT, Color.GREEN)}; - } - - public Vehicle[] vehicles() { - return vehicles; - } - } - - - private static class Vehicle extends TreeNode - { - private VehicleType vehicleType; - public final static String VEHICLE_TYPE_PROPERTY = "vehicleType"; - - private Color color; - public final static String COLOR_PROPERTY = "color"; - - private boolean greyed = false; - public final static String GREYED_PROPERTY = "greyed"; - - private boolean translucent = false; - public final static String TRANSLUCENT_PROPERTY = "translucent"; - - private Image image; - - - public Vehicle(TreeNode parent, VehicleType vehicleType, Color color) { - super(parent); - this.vehicleType = vehicleType; - this.color = color; - } - - public VehicleType vehicleType() { - return vehicleType; - } - - public void setVehicleType(VehicleType newVehicleType) { - VehicleType oldVehicleType = vehicleType; - vehicleType = newVehicleType; - firePropertyChanged(VEHICLE_TYPE_PROPERTY, oldVehicleType, newVehicleType); - } - - public Color color() { - return color; - } - - public void setColor(Color newColor) { - Color oldColor = color; - color = newColor; - firePropertyChanged(COLOR_PROPERTY, oldColor, newColor); - } - - public boolean isGreyed() { - return greyed; - } - - public void setGreyed(boolean newGreyed) { - boolean oldGreyed = greyed; - greyed = newGreyed; - firePropertyChanged(GREYED_PROPERTY, oldGreyed, newGreyed); - } - - public boolean isTranslucent() { - return translucent; - } - - public void setTranslucent(boolean newTranslucent) { - boolean oldTranslucent = translucent; - translucent = newTranslucent; - firePropertyChanged(TRANSLUCENT_PROPERTY, oldTranslucent, newTranslucent); - } - - public Image image() { - if (image != null) { - image.dispose(); - } - - return ImageFactory.image(color(), greyed, translucent); - } - } - - - private static enum VehicleType - { - BICYCLE("bicycle"), - CAR("car"), - TRUCK("truck"), - BOAT("boat"); - - private final String description; - - private VehicleType(String description) { - this.description = description; - } - - public String description() { - return description; - } - - @Override - public String toString() { - return description(); - } - } - - - private static enum Color - { - RED("red", new RGB(255, 0, 0)), - BLUE("blue", new RGB(0, 0, 255)), - YELLOW("yellow", new RGB(255, 255, 0)), - GREEN("green", new RGB(0, 255, 0)); - - private final String description; - - private final RGB rgb; - - private Color(String description, RGB rgb) { - this.description = description; - this.rgb = rgb; - } - - public String description() { - return description; - } - - public RGB rgb() { - return rgb; - } - - @Override - public String toString() { - return description(); - } - } - - - private static class ImageFactory - { - private static RGB rgb(Color color, boolean greyed, boolean translucent) { - RGB rgb = (greyed) ? new RGB(127, 127, 127) : color.rgb(); - if (translucent) { - rgb = new RGB(translucify(rgb.red), translucify(rgb.green), translucify(rgb.blue)); - } - return rgb; - } - - private static int translucify(int color) { - return 255 - (int) ((255 - color) * 0.3); - } - - public static Image image(Color color, boolean greyed, boolean translucent) { - PaletteData pd = new PaletteData(new RGB[] {rgb(color, greyed, translucent)}); - ImageData id = new ImageData(20, 20, 1, pd); - for (int x = 0; x < 20; x ++) { - for (int y = 0; y < 20; y ++) { - id.setPixel(x, y, 0); - } - } - return new Image(Display.getCurrent(), id); - } - } -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java deleted file mode 100644 index c35ad607fb..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/jface/DelegatingTreeContentProviderUiTest.java +++ /dev/null @@ -1,570 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 Oracle. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Oracle - initial API and implementation - *******************************************************************************/ -package org.eclipse.jpt.ui.tests.internal.jface; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.BaseLabelProvider; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreeViewer; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.jface.AbstractTreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingContentAndLabelProvider; -import org.eclipse.jpt.ui.internal.jface.DelegatingTreeContentAndLabelProvider; -import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProvider; -import org.eclipse.jpt.ui.internal.jface.ITreeItemContentProviderFactory; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.FilteringIterator; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyListIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.internal.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.CompositeCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListCollectionValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.StaticCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -public class DelegatingTreeContentProviderUiTest extends ApplicationWindow -{ - private final Root root; - - private WritablePropertyValueModel<TreeNode> selectedNode; - - private TreeViewer controlTree; - - private TreeViewer viewTree; - - private Text nodeNameText; - - - public static void main(String[] args) { - Window window = new DelegatingTreeContentProviderUiTest(args); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - private DelegatingTreeContentProviderUiTest(String[] args) { - super(null); - this.root = new Root(); - this.root.addChild("Parent_1"); - this.selectedNode = new SimplePropertyValueModel<TreeNode>(this.root); - } - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(ClassTools.shortClassNameForObject(this)); - parent.setSize(800, 400); - parent.setLayout(new GridLayout()); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayoutData(new GridData(GridData.FILL_BOTH)); - mainPanel.setLayout(new GridLayout()); - buildTreePanel(mainPanel); - buildControlPanel(mainPanel); - return mainPanel; - } - - private void buildTreePanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayoutData(new GridData(GridData.FILL_BOTH)); - panel.setLayout(new GridLayout(2, true)); - buildControlTreePanel(panel); - buildViewTreePanel(panel); - } - - private void buildControlTreePanel(Composite parent) { - controlTree = buildTreePanel( - parent, "Control tree", - new DelegatingTreeContentAndLabelProvider(new ControlTreeItemContentProviderFactory()), - new LabelProvider()); - controlTree.addSelectionChangedListener(buildTreeSelectionChangedListener()); - selectedNode.addPropertyChangeListener( - PropertyValueModel.VALUE, - new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - controlTree.setSelection(new StructuredSelection(event.newValue())); - } - } - ); - } - - private void buildViewTreePanel(Composite parent) { - viewTree = buildTreePanel( - parent, "View tree", - new DelegatingTreeContentAndLabelProvider(new ViewTreeItemContentProviderFactory()), - new LabelProvider()); - } - - private TreeViewer buildTreePanel(Composite parent, String labelText, ITreeContentProvider contentProvider, ILabelProvider labelProvider) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayoutData(new GridData(GridData.FILL_BOTH)); - panel.setLayout(new GridLayout()); - - Label label = new Label(panel, SWT.LEFT); - label.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, false, false)); - label.setText(labelText); - - final TreeViewer tree = new TreeViewer(panel, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); - tree.getTree().setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); - tree.setContentProvider(contentProvider); - tree.setLabelProvider(labelProvider); - tree.setInput(root); - - return tree; - } - - private ISelectionChangedListener buildTreeSelectionChangedListener() { - return new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - TreeNode selection = (TreeNode) ((IStructuredSelection) event.getSelection()).getFirstElement(); - selectedNode.setValue((selection == null) ? root : selection); - } - }; - } - - private void buildControlPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, false)); - panel.setLayout(new GridLayout(6, false)); - buildNodeNameText(panel); - buildAddChildACI().fill(panel); - buildAddNestedChildACI().fill(panel); - buildRemoveACI().fill(panel); - buildClearModelACI().fill(panel); - buildRestoreModelACI().fill(panel); - } - - private void buildNodeNameText(Composite parent) { - nodeNameText = new Text(parent, SWT.SINGLE | SWT.BORDER); - nodeNameText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false)); - } - - private ActionContributionItem buildAddChildACI() { - final Action action = new Action("Add child", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - addChild(); - } - }; - action.setToolTipText("Add a child with the given name"); - selectedNode.addPropertyChangeListener( - PropertyValueModel.VALUE, - new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - action.setEnabled(((TreeNode) event.newValue()).canHaveChildren()); - } - } - ); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildAddNestedChildACI() { - final Action action = new Action("Add nested child", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - addNestedChild(); - } - }; - action.setToolTipText("Add a nested child with the given name"); - action.setEnabled(false); - selectedNode.addPropertyChangeListener( - PropertyValueModel.VALUE, - new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - action.setEnabled(((TreeNode) event.newValue()).canHaveNestedChildren()); - } - } - ); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildRemoveACI() { - final Action action = new Action("Remove", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - remove(); - } - }; - action.setToolTipText("Remove the selected node"); - action.setEnabled(false); - selectedNode.addPropertyChangeListener( - PropertyValueModel.VALUE, - new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent event) { - action.setEnabled(event.newValue() != root); - } - } - ); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildClearModelACI() { - Action action = new Action("Clear model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - clearModel(); - } - }; - action.setToolTipText("Clear the model"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildRestoreModelACI() { - Action action = new Action("Restore model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - restoreModel(); - } - }; - action.setToolTipText("Restore the model"); - return new ActionContributionItem(action); - } - - void addChild() { - String nodeName = nodeNameText.getText(); - if (nodeName.length() != 0) { - selectedNode.value().addChild(nodeName); - } - } - - void addNestedChild() { - String nodeName = nodeNameText.getText(); - if (nodeName.length() != 0) { - selectedNode.value().addNestedChild(nodeName); - } - } - - void remove() { - TreeNode node = selectedNode.value(); - node.parent().removeChild(node); - } - - void clearModel() { - controlTree.setInput(null); - viewTree.setInput(null); - } - - void restoreModel() { - controlTree.setInput(root); - viewTree.setInput(root); - } - - - private static abstract class TreeItemContentProviderFactory - implements ITreeItemContentProviderFactory - { - public ITreeItemContentProvider buildItemContentProvider( - Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - return new GenericTreeItemContentProvider( - (TreeNode) item, (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider); - } - } - - - private static class ControlTreeItemContentProviderFactory extends TreeItemContentProviderFactory - { - - } - - - private static class ViewTreeItemContentProviderFactory - extends TreeItemContentProviderFactory - { - @Override - public ITreeItemContentProvider buildItemContentProvider( - Object item, DelegatingContentAndLabelProvider contentAndLabelProvider) { - if (item instanceof Parent) { - return new ViewTreeParentItemContentProvider( - (Parent) item, (DelegatingTreeContentAndLabelProvider) contentAndLabelProvider); - } - return super.buildItemContentProvider(item, contentAndLabelProvider); - } - } - - - private static class GenericTreeItemContentProvider extends AbstractTreeItemContentProvider<TreeNode> - { - public GenericTreeItemContentProvider( - TreeNode treeNode, DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider) { - super(treeNode, treeContentAndLabelProvider); - } - - protected TreeNode treeNode() { - return (TreeNode) model(); - } - - @Override - public TreeNode getParent() { - return treeNode().parent(); - } - - @Override - protected ListValueModel<TreeNode> buildChildrenModel() { - return new ListAspectAdapter<TreeNode, TreeNode>(TreeNode.CHILDREN_LIST, treeNode()) { - @Override - protected ListIterator<TreeNode> listIterator_() { - return treeNode().children(); - } - }; - } - } - - private static class ViewTreeParentItemContentProvider extends GenericTreeItemContentProvider - { - public ViewTreeParentItemContentProvider( - TreeNode treeNode, DelegatingTreeContentAndLabelProvider treeContentAndLabelProvider) { - super(treeNode, treeContentAndLabelProvider); - } - - @Override - public TreeNode getParent() { - TreeNode parent = super.getParent(); - if (parent instanceof Nest) { - parent = parent.parent(); - } - return parent; - } - - @Override - protected ListValueModel<TreeNode> buildChildrenModel() { - return buildChildrenModel( - new CompositeCollectionValueModel<TreeNode, TreeNode>(super.buildChildrenModel()) { - @Override - protected CollectionValueModel<TreeNode> transform(TreeNode value) { - if (value instanceof Nest) { - final Nest nest = (Nest) value; - return new ListCollectionValueModelAdapter<TreeNode>( - new ListAspectAdapter<TreeNode, TreeNode>(TreeNode.CHILDREN_LIST, nest) { - @Override - protected ListIterator<TreeNode> listIterator_() { - return nest.children(); - } - } - ); - } - else { - return new StaticCollectionValueModel<TreeNode>(CollectionTools.collection(value)); - } - } - } - ); - } - } - - - private static class LabelProvider extends BaseLabelProvider - implements ILabelProvider - { - public Image getImage(Object element) { - return null; - } - - public String getText(Object element) { - return ((TreeNode) element).getName(); - } - } - - - private static abstract class TreeNode extends AbstractModel - { - private TreeNode parent; - - protected final List<TreeNode> children; - public final static String CHILDREN_LIST = "children"; - - protected String name; - public final static String NAME_PROPERTY = "name"; - - - public TreeNode(TreeNode parent, String name) { - this.parent = parent; - this.children = new ArrayList<TreeNode>(); - this.name = name; - } - - public TreeNode parent() { - return parent; - } - - public ListIterator<TreeNode> children() { - return new ReadOnlyListIterator<TreeNode>(children); - } - - protected void addChild(TreeNode child) { - addItemToList(child, children, CHILDREN_LIST); - } - - public void removeChild(TreeNode child) { - removeItemFromList(child, children, CHILDREN_LIST); - } - - public void removeChild(int index) { - removeItemFromList(index, children, CHILDREN_LIST); - } - - public String getName() { - return name; - } - - public void setName(String newName) { - String oldName = name; - name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public boolean canHaveChildren() { - return false; - } - - public void addChild(String name) { - throw new UnsupportedOperationException(); - } - - public boolean canHaveNestedChildren() { - return false; - } - - public void addNestedChild(String name) { - throw new UnsupportedOperationException(); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(getName()); - } - } - - - private static class Root extends TreeNode - { - public Root() { - super(null, null); - } - - @Override - public boolean canHaveChildren() { - return true; - } - - @Override - public void addChild(String name) { - addChild(new Parent(this, name)); - } - } - - - private static class Parent extends TreeNode - { - public Parent(TreeNode parent, String name) { - super(parent, name); - } - - @Override - public boolean canHaveChildren() { - return true; - } - - @Override - public void addChild(String name) { - addChild(new Child(this, name)); - } - - @Override - public boolean canHaveNestedChildren() { - return true; - } - - @Override - public void addNestedChild(String name) { - TreeNode nest = new Nest(this); - addChild(nest); - nest.addChild(name); - } - - public Iterator<Child> nestlessChildren() { - return new FilteringIterator<Child, Child>( - new TransformationIterator<TreeNode, Child>(children()) { - @Override - protected Child transform(TreeNode next) { - if (next instanceof Nest) { - return ((Nest) next).child(); - } - return (Child) next; - } - }) { - @Override - protected boolean accept(Child c) { - return c != null; - } - }; - } - } - - - private static class Nest extends TreeNode - { - public Nest(TreeNode parent) { - super(parent, "nest"); - } - - @Override - public boolean canHaveChildren() { - return children.size() == 0; - } - - @Override - public void addChild(String name) { - addChild(new Child(this, name)); - } - - /* can only have one child */ - public Child child() { - return (children.isEmpty()) ? null : (Child) children.get(0); - } - } - - - private static class Child extends TreeNode - { - public Child(TreeNode parent, String name) { - super(parent, name); - } - } -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JpaPlatformUiExtensionTests.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JpaPlatformUiExtensionTests.java deleted file mode 100644 index d3ca0a1bb6..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JpaPlatformUiExtensionTests.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.eclipse.jpt.ui.tests.internal.platform; - -import junit.framework.TestCase; -import org.eclipse.jpt.core.internal.IJpaProject; -import org.eclipse.jpt.core.internal.platform.JpaPlatformRegistry; -import org.eclipse.jpt.core.tests.extension.resource.ExtensionTestPlugin; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatform; -import org.eclipse.jpt.core.tests.extension.resource.TestJpaPlatformUi; -import org.eclipse.jpt.core.tests.internal.ProjectUtility; -import org.eclipse.jpt.core.tests.internal.projects.TestJpaProject; - -public class JpaPlatformUiExtensionTests extends TestCase -{ - protected TestJpaProject testProject; - - protected static final String PROJECT_NAME = "ExtensionTestProject"; - protected static final String PACKAGE_NAME = "extension.test"; - - public static final String TEST_PLUGIN_CLASS = ExtensionTestPlugin.class.getName(); - public static final String TEST_PLUGIN_ID = ExtensionTestPlugin.PLUGIN_ID; - - public static final String TEST_PLATFORM_ID = TestJpaPlatform.ID; - public static final String TEST_PLATFORM_CLASS = TestJpaPlatform.class.getName(); - public static final String TEST_PLATFORM_LABEL = "Test Jpa Platform"; - - public static final String TEST_UI_PLATFORM_ID = TEST_PLATFORM_ID; - public static final String TEST_UI_PLATFORM_CLASS = TestJpaPlatformUi.class.getName(); - - public JpaPlatformUiExtensionTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.testProject = this.buildJpaProject(PROJECT_NAME, false); // false = no auto-build - } - - protected TestJpaProject buildJpaProject(String projectName, boolean autoBuild) throws Exception { - return new TestJpaProject(projectName, autoBuild); // false = no auto-build - } - - @Override - protected void tearDown() throws Exception { - //testProject.dispose(); - ProjectUtility.deleteAllProjects(); - this.testProject = null; - super.tearDown(); - } - - protected IJpaProject jpaProject() { - return this.testProject.getJpaProject(); - } - - public void testJpaPlatform() { - assertNotNull(JpaPlatformRegistry.instance().jpaPlatform(jpaProject().jpaPlatform().getId())); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JptUiPlatformTests.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JptUiPlatformTests.java deleted file mode 100644 index 50bcc99cfc..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/platform/JptUiPlatformTests.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.tests.internal.platform; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptUiPlatformTests -{ - public static Test suite() { - TestSuite suite = new TestSuite(JptUiPlatformTests.class.getPackage().getName()); - suite.addTestSuite(JpaPlatformUiExtensionTests.class); - return suite; - } - - private JptUiPlatformTests() { - super(); - throw new UnsupportedOperationException(); - } -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/CheckBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/CheckBoxModelAdapterUITest.java deleted file mode 100644 index 048ccf17f4..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/CheckBoxModelAdapterUITest.java +++ /dev/null @@ -1,318 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.tests.internal.swt; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.swt.BooleanButtonModelAdapter; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Play around with a set of check boxes. - */ -public class CheckBoxModelAdapterUITest - extends ApplicationWindow -{ - private final TestModel testModel; - private final WritablePropertyValueModel<TestModel> testModelHolder; - private final WritablePropertyValueModel<Boolean> flag1Holder; - private final WritablePropertyValueModel<Boolean> flag2Holder; - private final WritablePropertyValueModel<Boolean> notFlag2Holder; - - public static void main(String[] args) throws Exception { - Window window = new CheckBoxModelAdapterUITest(args); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - private CheckBoxModelAdapterUITest(String[] args) { - super(null); - this.testModel = new TestModel(true, true); - this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel); - this.flag1Holder = this.buildFlag1Holder(this.testModelHolder); - this.flag2Holder = this.buildFlag2Holder(this.testModelHolder); - this.notFlag2Holder = this.buildNotFlag2Holder(this.testModelHolder); - } - - private WritablePropertyValueModel<Boolean> buildFlag1Holder(PropertyValueModel<TestModel> subjectHolder) { - return new PropertyAspectAdapter<TestModel, Boolean>(subjectHolder, TestModel.FLAG1_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isFlag1()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setFlag1(value.booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildFlag2Holder(PropertyValueModel<TestModel> subjectHolder) { - return new PropertyAspectAdapter<TestModel, Boolean>(subjectHolder, TestModel.FLAG2_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isFlag2()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setFlag2(value.booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildNotFlag2Holder(PropertyValueModel<TestModel> subjectHolder) { - return new PropertyAspectAdapter<TestModel, Boolean>(subjectHolder, TestModel.NOT_FLAG2_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isNotFlag2()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setNotFlag2(value.booleanValue()); - } - }; - } - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(ClassTools.shortClassNameForObject(this)); - parent.setSize(400, 100); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayout(new FormLayout()); - Control checkBoxPanel = this.buildCheckBoxPanel(mainPanel); - this.buildControlPanel(mainPanel, checkBoxPanel); - return mainPanel; - } - - private Control buildCheckBoxPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100, -35); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildFlag1CheckBox(panel); - this.buildFlag2CheckBox(panel); - this.buildNotFlag2CheckBox(panel); - this.buildUnattachedCheckBox(panel); - - return panel; - } - - private void buildFlag1CheckBox(Composite parent) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText("flag 1"); - BooleanButtonModelAdapter.adapt(this.flag1Holder, checkBox); - } - - private void buildFlag2CheckBox(Composite parent) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText("flag 2"); - BooleanButtonModelAdapter.adapt(this.flag2Holder, checkBox); - } - - private void buildNotFlag2CheckBox(Composite parent) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText("not flag 2"); - BooleanButtonModelAdapter.adapt(this.notFlag2Holder, checkBox); - } - - private void buildUnattachedCheckBox(Composite parent) { - Button checkBox = new Button(parent, SWT.CHECK); - checkBox.setText("unattached"); - checkBox.addSelectionListener(this.buildUnattachedSelectionListener()); - } - - private SelectionListener buildUnattachedSelectionListener() { - return new SelectionListener() { - public void widgetDefaultSelected(SelectionEvent e) { - System.out.println("unattached default selected: " + e); - } - public void widgetSelected(SelectionEvent e) { - System.out.println("unattached selected: " + e); - } - }; - } - - private void buildControlPanel(Composite parent, Control checkBoxPanel) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(checkBoxPanel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildFlipFlag1Button(panel); - this.buildNotFlag2ToggleButton(panel); - this.buildClearModelButton(panel); - this.buildRestoreModelButton(panel); - this.buildPrintModelButton(panel); - } - - private void buildFlipFlag1Button(Composite parent) { - this.buildFlipFlag1ACI().fill(parent); - } - - private ActionContributionItem buildFlipFlag1ACI() { - Action action = new Action("flip flag 1", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - CheckBoxModelAdapterUITest.this.flipFlag1(); - } - }; - action.setToolTipText("flip flag 1"); - return new ActionContributionItem(action); - } - - void flipFlag1() { - this.testModel.setFlag1( ! this.testModel.isFlag1()); - } - - private void buildNotFlag2ToggleButton(Composite parent) { - Button checkBox = new Button(parent, SWT.TOGGLE); - checkBox.setText("not flag 2"); - BooleanButtonModelAdapter.adapt(this.notFlag2Holder, checkBox); - } - - private void buildClearModelButton(Composite parent) { - this.buildClearModelACI().fill(parent); - } - - private ActionContributionItem buildClearModelACI() { - Action action = new Action("clear model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - CheckBoxModelAdapterUITest.this.clearModel(); - } - }; - action.setToolTipText("clear model"); - return new ActionContributionItem(action); - } - - void clearModel() { - this.testModelHolder.setValue(null); - } - - private void buildRestoreModelButton(Composite parent) { - this.buildRestoreModelACI().fill(parent); - } - - private ActionContributionItem buildRestoreModelACI() { - Action action = new Action("restore model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - CheckBoxModelAdapterUITest.this.restoreModel(); - } - }; - action.setToolTipText("restore model"); - return new ActionContributionItem(action); - } - - void restoreModel() { - this.testModelHolder.setValue(this.testModel); - } - - private void buildPrintModelButton(Composite parent) { - this.buildPrintModelACI().fill(parent); - } - - private ActionContributionItem buildPrintModelACI() { - Action action = new Action("print model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - CheckBoxModelAdapterUITest.this.printModel(); - } - }; - action.setToolTipText("print model"); - return new ActionContributionItem(action); - } - - void printModel() { - System.out.println("flag 1: " + this.testModel.isFlag1()); - System.out.println("flag 2: " + this.testModel.isFlag2()); - System.out.println("not flag 2: " + this.testModel.isNotFlag2()); - System.out.println("***"); - } - - - private class TestModel extends AbstractModel { - private boolean flag1; - public static final String FLAG1_PROPERTY = "flag1"; - private boolean flag2; - public static final String FLAG2_PROPERTY = "flag2"; - private boolean notFlag2; - public static final String NOT_FLAG2_PROPERTY = "notFlag2"; - - public TestModel(boolean flag1, boolean flag2) { - this.flag1 = flag1; - this.flag2 = flag2; - this.notFlag2 = ! flag2; - } - public boolean isFlag1() { - return this.flag1; - } - public void setFlag1(boolean flag1) { - boolean old = this.flag1; - this.flag1 = flag1; - this.firePropertyChanged(FLAG1_PROPERTY, old, flag1); - } - public boolean isFlag2() { - return this.flag2; - } - public void setFlag2(boolean flag2) { - boolean old = this.flag2; - this.flag2 = flag2; - this.firePropertyChanged(FLAG2_PROPERTY, old, flag2); - - old = this.notFlag2; - this.notFlag2 = ! flag2; - this.firePropertyChanged(NOT_FLAG2_PROPERTY, old, this.notFlag2); - } - public boolean isNotFlag2() { - return this.notFlag2; - } - public void setNotFlag2(boolean notFlag2) { - this.setFlag2( ! notFlag2); - } - @Override - public String toString() { - return "TestModel(" + this.isFlag1() + " - " + this.isFlag2() + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/ListBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/ListBoxModelAdapterUITest.java deleted file mode 100644 index 1976428324..0000000000 --- a/jpa/tests/org.eclipse.jpt.ui.tests/src/org/eclipse/jpt/ui/tests/internal/swt/ListBoxModelAdapterUITest.java +++ /dev/null @@ -1,641 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 Oracle. All rights reserved. - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0, which accompanies this distribution - * and is available at http://www.eclipse.org/legal/epl-v10.html. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.ui.tests.internal.swt; - -import java.text.Collator; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.ActionContributionItem; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.window.ApplicationWindow; -import org.eclipse.jface.window.Window; -import org.eclipse.jpt.ui.internal.swt.ListBoxModelAdapter; -import org.eclipse.jpt.ui.internal.swt.ListBoxModelAdapter.SelectionChangeEvent; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.Model; -import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.WritablePropertyValueModel; -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * an example UI for testing various permutations of the - * StructuredContentProviderAdapter - */ -public class ListBoxModelAdapterUITest - extends ApplicationWindow -{ - final TaskList taskList; - private final WritablePropertyValueModel<TaskList> taskListHolder; - private Text taskTextField; - - public static void main(String[] args) throws Exception { - Window window = new ListBoxModelAdapterUITest(args); - window.setBlockOnOpen(true); - window.open(); - Display.getCurrent().dispose(); - System.exit(0); - } - - private ListBoxModelAdapterUITest(String[] args) { - super(null); - this.taskList = new TaskList(); - this.taskListHolder = new SimplePropertyValueModel<TaskList>(this.taskList); - this.taskList.addTask("swim"); - this.taskList.addTask("bike"); - this.taskList.addTask("run"); - Task rest = this.taskList.addTask("rest"); - this.taskList.addPriorityTask(rest); - Task repeat = this.taskList.addTask("repeat"); - this.taskList.addPriorityTask(repeat); - } - - @Override - protected Control createContents(Composite parent) { - ((Shell) parent).setText(ClassTools.shortClassNameForObject(this)); - parent.setSize(800, 400); - Composite mainPanel = new Composite(parent, SWT.NONE); - mainPanel.setLayout(new FormLayout()); - Control taskListPanel = this.buildTaskListPanel(mainPanel); - this.buildControlPanel(mainPanel, taskListPanel); - return mainPanel; - } - - private Control buildTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100, -30); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - this.buildPrimitiveTaskListPanel(panel); - this.buildObjectTaskListPanel(panel); - - return panel; - } - - private void buildPrimitiveTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(50); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildUnsortedPrimitiveListPanel(panel); - this.buildStandardSortedPrimitiveListPanel(panel); - this.buildCustomSortedPrimitiveListPanel(panel); - } - - private void buildObjectTaskListPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - - FormData fd = new FormData(); - fd.top = new FormAttachment(50); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildUnsortedObjectListPanel(panel); - this.buildStandardSortedObjectListPanel(panel); - this.buildCustomSortedObjectListPanel(panel); - } - - private void buildUnsortedPrimitiveListPanel(Composite parent) { - this.buildListPanel(parent, "primitive unsorted", this.buildUnsortedPrimitiveListModel(), new SimpleCollectionValueModel<String>()); - } - - private void buildStandardSortedPrimitiveListPanel(Composite parent) { - this.buildListPanel(parent, "primitive sorted", this.buildStandardSortedPrimitiveListModel(), new SimpleCollectionValueModel<String>()); - } - - private void buildCustomSortedPrimitiveListPanel(Composite parent) { - this.buildListPanel(parent, "primitive reverse sorted", this.buildCustomSortedPrimitiveListModel(), new SimpleCollectionValueModel<String>()); - } - - private void buildUnsortedObjectListPanel(Composite parent) { - this.buildListPanel2(parent, "object unsorted", this.buildUnsortedObjectListModel(), this.buildPriorityTaskListAdapter()); - } - - private void buildStandardSortedObjectListPanel(Composite parent) { - this.buildListPanel2(parent, "object sorted", this.buildStandardSortedObjectListModel(), this.buildPriorityTaskListAdapter()); - } - - private void buildCustomSortedObjectListPanel(Composite parent) { - this.buildListPanel2(parent, "object reverse sorted", this.buildCustomSortedObjectListModel(), this.buildPriorityTaskListAdapter()); - } - - private ListValueModel buildUnsortedPrimitiveListModel() { - return this.buildPrimitiveTaskListAdapter(); - } - - private ListValueModel buildStandardSortedPrimitiveListModel() { - return new SortedListValueModelAdapter(this.buildPrimitiveTaskListAdapter()); - } - - private ListValueModel buildCustomSortedPrimitiveListModel() { - return new SortedListValueModelAdapter(this.buildPrimitiveTaskListAdapter(), this.buildCustomStringComparator()); - } - - private ListValueModel buildUnsortedObjectListModel() { - return this.buildObjectTaskListAdapter(); - } - - private ListValueModel buildStandardSortedObjectListModel() { - return new SortedListValueModelAdapter(this.buildObjectTaskListAdapter()); - } - - private ListValueModel buildCustomSortedObjectListModel() { - return new SortedListValueModelAdapter(this.buildObjectTaskListAdapter(), this.buildCustomTaskComparator()); - } - - private ListBoxModelAdapter buildListPanel(Composite parent, String label, ListValueModel model, CollectionValueModel selectedItemsModel) { - Composite panel = new Composite(parent, SWT.NONE); - panel.setLayout(new FormLayout()); - - Label listLabel = new Label(panel, SWT.LEFT | SWT.VERTICAL); - listLabel.setText(label); - FormData fd = new FormData(); - fd.top = new FormAttachment(0, 3); - fd.bottom = new FormAttachment(0, 20); - fd.left = new FormAttachment(0, 5); - fd.right = new FormAttachment(100); - listLabel.setLayoutData(fd); - - org.eclipse.swt.widgets.List listBox = new org.eclipse.swt.widgets.List(panel, SWT.MULTI | SWT.BORDER); - fd = new FormData(); - fd.top = new FormAttachment(listLabel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - listBox.setLayoutData(fd); - return ListBoxModelAdapter.adapt(model, selectedItemsModel, listBox); // use #toString() - } - - private void buildListPanel2(Composite parent, String label, ListValueModel model, CollectionValueModel selectedItemsModel) { - ListBoxModelAdapter<Task> adapter = this.buildListPanel(parent, label, model, selectedItemsModel); - adapter.addDoubleClickListener(this.buildDoubleClickListener()); - adapter.addSelectionChangeListener(this.buildSelectionChangeListener()); - } - - private ListBoxModelAdapter.DoubleClickListener<Task> buildDoubleClickListener() { - return new ListBoxModelAdapter.DoubleClickListener<Task>() { - public void doubleClick(ListBoxModelAdapter.DoubleClickEvent<Task> event) { - System.out.println("double-click: " + event.selection()); - } - }; - } - - private ListBoxModelAdapter.SelectionChangeListener<Task> buildSelectionChangeListener() { - return new ListBoxModelAdapter.SelectionChangeListener<Task>() { - public void selectionChanged(SelectionChangeEvent<Task> event) { - ListBoxModelAdapterUITest.this.taskList.setPriorityTasks(event.selection()); - } - }; - } - - private Comparator<String> buildCustomStringComparator() { - return new Comparator<String>() { - public int compare(String s1, String s2) { - return s2.compareTo(s1); - } - }; - } - - private Comparator<Task> buildCustomTaskComparator() { - return new Comparator<Task>() { - public int compare(Task to1, Task to2) { - return to2.compareTo(to1); - } - }; - } - - private ListValueModel buildPrimitiveTaskListAdapter() { - return new ListAspectAdapter(this.taskListHolder, TaskList.TASK_NAMES_LIST) { - @Override - protected ListIterator<String> listIterator_() { - return ((TaskList) this.subject).taskNames(); - } - }; - } - - private ListValueModel buildObjectTaskListAdapter() { - return new ListAspectAdapter(this.taskListHolder, TaskList.TASKS_LIST) { - @Override - protected ListIterator<Task> listIterator_() { - return ((TaskList) this.subject).tasks(); - } - }; - } - - private CollectionValueModel buildPriorityTaskListAdapter() { - return new CollectionAspectAdapter(this.taskListHolder, TaskList.PRIORITY_TASKS_COLLECTION) { - @Override - protected Iterator<Task> iterator_() { - return ((TaskList) this.subject).priorityTasks(); - } - }; - } - - private void buildControlPanel(Composite parent, Control taskListPanel) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(taskListPanel); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - Control misc = this.buildMiscTaskPanel(panel); - this.buildAddRemoveTaskPanel(panel, misc); - } - - // is there a better way to associate an ACI with form data? - private Control buildMiscTaskPanel(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(100, -400); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildClearListACI().fill(panel); - this.buildClearModelACI().fill(panel); - this.buildRestoreModelACI().fill(panel); - this.buildAddPriorityTaskACI().fill(panel); - this.buildRemovePriorityTaskACI().fill(panel); - this.buildClearPriorityTasksACI().fill(panel); - return panel; - } - - private ActionContributionItem buildClearListACI() { - Action action = new Action("clear list", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelAdapterUITest.this.clearTasks(); - } - }; - action.setToolTipText("clear all the tasks"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildClearModelACI() { - Action action = new Action("clear model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelAdapterUITest.this.clearModel(); - } - }; - action.setToolTipText("clear the task list model"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildRestoreModelACI() { - Action action = new Action("restore model", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelAdapterUITest.this.restoreModel(); - } - }; - action.setToolTipText("restore the task list model"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildAddPriorityTaskACI() { - Action action = new Action("add priority", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelAdapterUITest.this.addPriorityTask(); - } - }; - action.setToolTipText("add a task to the priority tasks"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildRemovePriorityTaskACI() { - Action action = new Action("remove priority", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelAdapterUITest.this.removePriorityTask(); - } - }; - action.setToolTipText("remove a task from the priority tasks"); - return new ActionContributionItem(action); - } - - private ActionContributionItem buildClearPriorityTasksACI() { - Action action = new Action("clear priority", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelAdapterUITest.this.clearPriorityTasks(); - } - }; - action.setToolTipText("clear the priority tasks"); - return new ActionContributionItem(action); - } - - private void buildAddRemoveTaskPanel(Composite parent, Control clearButton) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(clearButton); - panel.setLayoutData(fd); - - panel.setLayout(new FormLayout()); - Control addButton = this.buildAddButton(panel); - Control removeButton = this.buildRemoveButton(panel); - this.buildTaskTextField(panel, addButton, removeButton); - } - - // is there a better way to associate an ACI with form data? - private Control buildAddButton(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(0); - fd.right = new FormAttachment(0, 50); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildAddACI().fill(panel); - return panel; - } - - private ActionContributionItem buildAddACI() { - Action action = new Action("add", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelAdapterUITest.this.addTask(); - } - }; - action.setToolTipText("add a task with the name in the entry field"); - return new ActionContributionItem(action); - } - - // is there a better way to associate an ACI with form data? - private Control buildRemoveButton(Composite parent) { - Composite panel = new Composite(parent, SWT.NONE); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(100, -50); - fd.right = new FormAttachment(100); - panel.setLayoutData(fd); - - panel.setLayout(new FillLayout()); - this.buildRemoveACI().fill(panel); - return panel; - } - - private ActionContributionItem buildRemoveACI() { - Action action = new Action("remove", IAction.AS_PUSH_BUTTON) { - @Override - public void run() { - ListBoxModelAdapterUITest.this.removeTask(); - } - }; - action.setToolTipText("remove the task with the name in the entry field"); - return new ActionContributionItem(action); - } - - private void buildTaskTextField(Composite parent, Control addButton, Control removeButton) { - this.taskTextField = new Text(parent, SWT.SINGLE | SWT.BORDER); - FormData fd = new FormData(); - fd.top = new FormAttachment(0); - fd.bottom = new FormAttachment(100); - fd.left = new FormAttachment(addButton); - fd.right = new FormAttachment(removeButton); - this.taskTextField.setLayoutData(fd); - } - - private String taskTextFieldText() { - return this.taskTextField.getText(); - } - - void addTask() { - String taskText = this.taskTextFieldText(); - if (taskText.length() != 0) { - this.taskList.addTask(taskText); - } - } - - void removeTask() { - String task = this.taskTextFieldText(); - if (task.length() != 0) { - this.taskList.removeTask(task); - } - } - - void clearTasks() { - this.taskList.clearTasks(); - } - - void clearModel() { - this.taskListHolder.setValue(null); - } - - void restoreModel() { - this.taskListHolder.setValue(this.taskList); - } - - void addPriorityTask() { - Iterator<Task> tasks = this.taskList.tasks(); - while (tasks.hasNext()) { - if (this.taskList.addPriorityTask(tasks.next())) { - return; - } - } - } - - void removePriorityTask() { - Iterator<Task> pTasks = this.taskList.priorityTasks(); - if (pTasks.hasNext()) { - this.taskList.removePriorityTask(pTasks.next()); - } - } - - void clearPriorityTasks() { - this.taskList.clearPriorityTasks(); - } - - - // ********** TaskList ********** - - // note absence of validation... - private class TaskList extends AbstractModel { - private final List<String> taskNames = new ArrayList<String>(); - public static final String TASK_NAMES_LIST = "taskNames"; - private final List<Task> tasks = new ArrayList<Task>(); - public static final String TASKS_LIST = "tasks"; - private final Collection<Task> priorityTasks = new HashSet<Task>(); - public static final String PRIORITY_TASKS_COLLECTION = "priorityTasks"; - TaskList() { - super(); - } - public ListIterator<String> taskNames() { - return this.taskNames.listIterator(); - } - public ListIterator<Task> tasks() { - return this.tasks.listIterator(); - } - public Iterator<Task> priorityTasks() { - return this.priorityTasks.iterator(); - } - public Task addTask(String taskName) { - this.addItemToList(taskName, this.taskNames, TASK_NAMES_LIST); - Task task = new Task(taskName); - this.addItemToList(task, this.tasks, TASKS_LIST); - return task; - } - public void removeTask(String taskName) { - int index = this.taskNames.indexOf(taskName); - if (index != -1) { - this.removeItemFromList(index, this.taskNames, TASK_NAMES_LIST); - // assume the indexes match... - Task removedTask = this.removeItemFromList(index, this.tasks, TASKS_LIST); - this.removeItemFromCollection(removedTask, this.priorityTasks, PRIORITY_TASKS_COLLECTION); - } - } - public void clearTasks() { - this.taskNames.clear(); - this.fireListCleared(TASK_NAMES_LIST); - this.tasks.clear(); - this.fireListCleared(TASKS_LIST); - } - public boolean addPriorityTask(Task task) { - return this.addItemToCollection(task, this.priorityTasks, PRIORITY_TASKS_COLLECTION); - } - public void removePriorityTask(Task task) { - this.removeItemFromCollection(task, this.priorityTasks, PRIORITY_TASKS_COLLECTION); - } - public void clearPriorityTasks() { - this.clearCollection(this.priorityTasks, PRIORITY_TASKS_COLLECTION); - } - public void setPriorityTasks(Iterator<Task> tasks) { - this.priorityTasks.clear(); - while (tasks.hasNext()) { - this.priorityTasks.add(tasks.next()); - } - this.fireCollectionChanged(PRIORITY_TASKS_COLLECTION); - } - } - - - // ********** Task ********** - - private class Task extends AbstractModel implements Displayable { - private String name; - private Date creationTimeStamp; - public Task(String name) { - this.name = name; - this.creationTimeStamp = new Date(); - } - public String displayString() { - return this.name + ": " + this.creationTimeStamp.getTime(); - } - public int compareTo(Displayable o) { - return DEFAULT_COMPARATOR.compare(this, o); - } - public String getName() { - return this.name; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(DISPLAY_STRING_PROPERTY, old, name); - } - @Override - public String toString() { - return this.displayString(); - } - } - - public interface Displayable extends Model, Comparable<Displayable> { - - String displayString(); - String DISPLAY_STRING_PROPERTY = "displayString"; - - - // ********** helper implementations ********** - - Collator DEFAULT_COLLATOR = Collator.getInstance(); - - Comparator<Displayable> DEFAULT_COMPARATOR = - new Comparator<Displayable>() { - public int compare(Displayable d1, Displayable d2) { - // disallow duplicates based on object identity - if (d1 == d2) { - return 0; - } - - // first compare display strings using the default collator - int result = DEFAULT_COLLATOR.compare(d1.displayString(), d2.displayString()); - if (result != 0) { - return result; - } - - // then compare using object-id - result = System.identityHashCode(d1) - System.identityHashCode(d2); - if (result != 0) { - return result; - } - - // It's unlikely that we get to this point; but, just in case, we will return -1. - // Unfortunately, this introduces some mild unpredictability to the sort order - // (unless the objects are always passed into this method in the same order). - return -1; // if all else fails, indicate that o1 < o2 - } - @Override - public String toString() { - return "Displayable.DEFAULT_COMPARATOR"; - } - }; - - } -} |