You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(7) |
Aug
|
Sep
(46) |
Oct
(102) |
Nov
(10) |
Dec
(21) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(1) |
Feb
(3) |
Mar
(14) |
Apr
(9) |
May
(12) |
Jun
(4) |
Jul
(40) |
Aug
(60) |
Sep
(38) |
Oct
(2) |
Nov
(1) |
Dec
(42) |
2008 |
Jan
(23) |
Feb
(29) |
Mar
(107) |
Apr
(27) |
May
(3) |
Jun
(1) |
Jul
(15) |
Aug
(7) |
Sep
(19) |
Oct
|
Nov
(2) |
Dec
|
2009 |
Jan
(36) |
Feb
(4) |
Mar
(2) |
Apr
(1) |
May
(1) |
Jun
(15) |
Jul
(30) |
Aug
(32) |
Sep
(11) |
Oct
(21) |
Nov
(12) |
Dec
(15) |
2010 |
Jan
(29) |
Feb
(9) |
Mar
(25) |
Apr
|
May
(7) |
Jun
(5) |
Jul
(21) |
Aug
(32) |
Sep
(10) |
Oct
(8) |
Nov
(29) |
Dec
(8) |
2011 |
Jan
(9) |
Feb
(35) |
Mar
(11) |
Apr
(4) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(30) |
2012 |
Jan
(5) |
Feb
(7) |
Mar
(10) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <mwl...@us...> - 2009-12-30 20:55:10
|
Revision: 1002 http://cishell.svn.sourceforge.net/cishell/?rev=1002&view=rev Author: mwlinnem Date: 2009-12-30 20:55:04 +0000 (Wed, 30 Dec 2009) Log Message: ----------- Whitespace correction. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-30 20:53:59 UTC (rev 1001) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-30 20:55:04 UTC (rev 1002) @@ -140,7 +140,6 @@ DataSource dataSource = new PoolingDataSource(connectionPool); //test the connection (this will throw an exception if the connection is faulty) - dataSource.getConnection(); //return that data source. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-12-30 20:54:07
|
Revision: 1001 http://cishell.svn.sourceforge.net/cishell/?rev=1001&view=rev Author: mwlinnem Date: 2009-12-30 20:53:59 +0000 (Wed, 30 Dec 2009) Log Message: ----------- We now attempt to connect to the new data sources we create. This way if the connection is faulty we'll get an error immediately rather than when we try to use it later. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-30 17:41:04 UTC (rev 1000) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-30 20:53:59 UTC (rev 1001) @@ -139,11 +139,17 @@ connectionFactory, connectionPool, stmtPool, null, false, true); DataSource dataSource = new PoolingDataSource(connectionPool); + //test the connection (this will throw an exception if the connection is faulty) + + dataSource.getConnection(); + //return that data source. return dataSource; } catch (ClassNotFoundException e) { throw new DatabaseCreationException( "Database driver '" + driver + "' could not be found", e); + } catch (SQLException e) { + throw new DatabaseCreationException(e.getMessage(), e); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-12-30 17:41:11
|
Revision: 1000 http://cishell.svn.sourceforge.net/cishell/?rev=1000&view=rev Author: pataphil Date: 2009-12-30 17:41:04 +0000 (Wed, 30 Dec 2009) Log Message: ----------- * Added all versions of NumberUtilities.isEven() and NumberUtilities.isOdd(). Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-12-23 19:53:05 UTC (rev 999) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/NumberUtilities.java 2009-12-30 17:41:04 UTC (rev 1000) @@ -132,4 +132,28 @@ return numberAsString; } } + + public static boolean isEven(long number) { + return ((number % 2) == 0); + } + + public static boolean isEven(float number) { + return ((number % 2) == 0); + } + + public static boolean isEven(double number) { + return ((number % 2) == 0); + } + + public static boolean isOdd(long target) { + return !isEven(target); + } + + public static boolean isOdd(float target) { + return !isEven(target); + } + + public static boolean isOdd(double target) { + return !isEven(target); + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-12-23 19:53:13
|
Revision: 999 http://cishell.svn.sourceforge.net/cishell/?rev=999&view=rev Author: mwlinnem Date: 2009-12-23 19:53:05 +0000 (Wed, 23 Dec 2009) Log Message: ----------- Added TODO. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2009-12-23 17:48:13 UTC (rev 998) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2009-12-23 19:53:05 UTC (rev 999) @@ -60,7 +60,7 @@ throws FileViewingException { try { String dataFormat = data.getFormat(); - + //TODO: Add image viewing support here (shouldn't be too hard) if (isCSVFormat(data)) { /* * The data is already a CSV file, so it just needs to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-12-23 17:48:20
|
Revision: 998 http://cishell.svn.sourceforge.net/cishell/?rev=998&view=rev Author: mwlinnem Date: 2009-12-23 17:48:13 +0000 (Wed, 23 Dec 2009) Log Message: ----------- Minor changes based on Patrick's suggestions. Reviewed by Patrick. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-23 16:07:47 UTC (rev 997) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-23 17:48:13 UTC (rev 998) @@ -3,10 +3,10 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; +import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.Hashtable; -import java.util.Iterator; import java.util.List; import javax.sql.DataSource; @@ -45,7 +45,7 @@ * internal databases are created when requested by outside services, * and are cleaned and shut down when this service is stopped. */ - private List internalDatabases = new ArrayList(); + private List<InternalDerbyDatabase> internalDatabases = new ArrayList<InternalDerbyDatabase>(); public final void start(BundleContext context) throws Exception { @@ -55,7 +55,7 @@ */ System.setProperty("derby.system.home", DATABASE_DIRECTORY); - //allow the database service to be found by other services/plugins + //Allow the database service to be found by other services/plugins databaseServiceRegistration = context.registerService( DatabaseService.class.getName(), this, new Hashtable()); } @@ -64,10 +64,9 @@ //disallow the database service to be found by other services/plugins this.databaseServiceRegistration.unregister(); - //try to clean out the internal databases and shut them down. + //Clean out the internal databases and shut them down. try { - for (Iterator it = internalDatabases.iterator(); it.hasNext();) { - InternalDerbyDatabase internalDatabase = (InternalDerbyDatabase) it.next(); + for (InternalDerbyDatabase internalDatabase : internalDatabases) { Connection internalDatabaseConnection = internalDatabase.getConnection(); removeAllNonSystemDatabaseTables(internalDatabaseConnection); internalDatabase.shutdown(); @@ -90,7 +89,7 @@ try { //connect to and create a 'new' database String databaseName = INTERNAL_DB_NAME_PREFIX + id; - Database db = new InternalDerbyDatabase(createNewInternalDataSource(databaseName)); + InternalDerbyDatabase db = new InternalDerbyDatabase(createNewInternalDataSource(databaseName)); //if this database existed on disk from a previous session, clean it to be like new removeAllNonSystemDatabaseTables(db.getConnection()); @@ -160,7 +159,8 @@ private static final int TABLE_NAME_INDEX = 3; private static final String NONSYSTEM_SCHEMA_NAME = "APP"; - private void removeAllNonSystemDatabaseTables(Connection dbConnection) throws Exception { + //(removes all non-system tables from the provided databases) + private void removeAllNonSystemDatabaseTables(Connection dbConnection) throws SQLException { DatabaseMetaData dbMetadata = dbConnection.getMetaData(); ResultSet allTableNames = dbMetadata.getTables(null, null, null, null); @@ -168,10 +168,8 @@ while (allTableNames.next()) { if (!hasSystemSchema(allTableNames.getString(SCHEMA_NAME_INDEX))) { - String removeTableSQL = - "DROP TABLE " - + NONSYSTEM_SCHEMA_NAME + "." + allTableNames.getString(TABLE_NAME_INDEX); - removeTables.addBatch(removeTableSQL); + String dropTableQuery = allTableNames.getString(TABLE_NAME_INDEX); + removeTables.addBatch(dropTableQuery); } } @@ -181,4 +179,11 @@ private boolean hasSystemSchema(String tableSchemaName) { return tableSchemaName.indexOf(NONSYSTEM_SCHEMA_NAME) == -1; } + + private String formDropTableQuery(String tableName) { + String removeTableSQL = + "DROP TABLE " + + NONSYSTEM_SCHEMA_NAME + "." + tableName; + return removeTableSQL; + } } Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java 2009-12-23 16:07:47 UTC (rev 997) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java 2009-12-23 17:48:13 UTC (rev 998) @@ -24,7 +24,7 @@ * Will want to discuss security implications here. */ public Connection getConnection(String username, String password) - throws SQLException { + throws SQLException { return dataSource.getConnection(username, password); } } Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2009-12-23 16:07:47 UTC (rev 997) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2009-12-23 17:48:13 UTC (rev 998) @@ -26,7 +26,5 @@ DerbyDatabaseService.DERBY_PROTOCOL + DerbyDatabaseService.DEFAULT_SHUTDOWN_CONNECTION_STRING; DriverManager.getConnection(shutdownDatabaseCommand); - - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-12-23 16:07:56
|
Revision: 997 http://cishell.svn.sourceforge.net/cishell/?rev=997&view=rev Author: mwlinnem Date: 2009-12-23 16:07:47 +0000 (Wed, 23 Dec 2009) Log Message: ----------- Cleanup. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/.project trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java Added Paths: ----------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java Removed Paths: ------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java Modified: trunk/core/org.cishell.reference.service.database/.project =================================================================== --- trunk/core/org.cishell.reference.service.database/.project 2009-12-21 21:30:24 UTC (rev 996) +++ trunk/core/org.cishell.reference.service.database/.project 2009-12-23 16:07:47 UTC (rev 997) @@ -20,9 +20,15 @@ <arguments> </arguments> </buildCommand> + <buildCommand> + <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> + <arguments> + </arguments> + </buildCommand> </buildSpec> <natures> <nature>org.eclipse.pde.PluginNature</nature> <nature>org.eclipse.jdt.core.javanature</nature> + <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> </natures> </projectDescription> Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-21 21:30:24 UTC (rev 996) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-23 16:07:47 UTC (rev 997) @@ -31,6 +31,7 @@ public static final String DERBY_DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver"; public static final String DERBY_PROTOCOL = "jdbc:derby:"; + public static final String DEFAULT_CREATE_CONNECTION_STRING = ";create=true"; public static final String DEFAULT_SHUTDOWN_CONNECTION_STRING =";shutdown=true"; @@ -40,53 +41,56 @@ //hold on to our service registration so we can unregister when this plugin stops. private ServiceRegistration databaseServiceRegistration; + /* + * internal databases are created when requested by outside services, + * and are cleaned and shut down when this service is stopped. + */ private List internalDatabases = new ArrayList(); - public void start(BundleContext context) throws Exception { + public final void start(BundleContext context) throws Exception { /* * Tell Derby to look for an existing database or create a new database - * in the default directory (within our application's directory) + * in the default directory (within our application's directory) */ System.setProperty("derby.system.home", DATABASE_DIRECTORY); //allow the database service to be found by other services/plugins - databaseServiceRegistration = context.registerService - (DatabaseService.class.getName(), this, new Hashtable()); + databaseServiceRegistration = context.registerService( + DatabaseService.class.getName(), this, new Hashtable()); } - public void stop(BundleContext context) { + public final void stop(BundleContext context) { //disallow the database service to be found by other services/plugins this.databaseServiceRegistration.unregister(); - //try to clean out the databases and shut them down. + //try to clean out the internal databases and shut them down. try { - - for (Iterator it = internalDatabases.iterator(); it.hasNext();) { - InternalDerbyDatabase activeDatabase = (InternalDerbyDatabase) it.next(); - Connection activeDatabaseConnection = activeDatabase.getConnection(); - removeAllNonSystemDatabaseTables(activeDatabaseConnection); - activeDatabase.shutdown(); + InternalDerbyDatabase internalDatabase = (InternalDerbyDatabase) it.next(); + Connection internalDatabaseConnection = internalDatabase.getConnection(); + removeAllNonSystemDatabaseTables(internalDatabaseConnection); + internalDatabase.shutdown(); } } catch (Exception e) { String message = - "An unexpected exception occurred while shutting down the internal database." + - "Aborting database shutdown process." + - "Database may not be left in a valid state (but it will probably be okay)."; + "An unexpected exception occurred while shutting down the internal database." + + "Aborting database shutdown process." + + "Database may not be left in a valid state, " + + "but we will try to make its state valid on next startup."; throw new RuntimeException(message, e); } } - private static final String DB_NAME_PREFIX = "cishell_database"; + private static final String INTERNAL_DB_NAME_PREFIX = "cishell_database"; private static int id = 0; public synchronized Database createNewDatabase() throws DatabaseCreationException { try { //connect to and create a 'new' database - String databaseName = DB_NAME_PREFIX + id; - Database db = new InternalDerbyDatabase(databaseName, createNewInternalDataSource(databaseName)); + String databaseName = INTERNAL_DB_NAME_PREFIX + id; + Database db = new InternalDerbyDatabase(createNewInternalDataSource(databaseName)); //if this database existed on disk from a previous session, clean it to be like new removeAllNonSystemDatabaseTables(db.getConnection()); @@ -95,6 +99,7 @@ internalDatabases.add(db); id++; + return db; } catch (Exception e) { throw new DatabaseCreationException(e); @@ -111,9 +116,7 @@ throws DatabaseCreationException { DataSource dataSource = createNewDataSource(driver, url, username, password); - //TODO: change Database to support non-derby urls and whatnot Database db = new ExternalDatabase(dataSource); - //(assuming we don't need to keep track of these databases, as we will not close them on shutdown) return db; } @@ -128,27 +131,28 @@ //Load the database driver Class.forName(driver); - ConnectionFactory connectionFactory = new DriverManagerConnectionFactory - (url, username, password); + //create a new data source based on the database connection info provided. + ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( + url, username, password); GenericObjectPool connectionPool = new GenericObjectPool(); KeyedObjectPoolFactory stmtPool = new GenericKeyedObjectPoolFactory(null); - //(side-effects) - new PoolableConnectionFactory(connectionFactory, connectionPool, stmtPool, null, false, true); - //(creating the data source this way is probably overkill for our current purposes, - //(but I don't imagine it does much harm either). + new PoolableConnectionFactory( + connectionFactory, connectionPool, stmtPool, null, false, true); DataSource dataSource = new PoolingDataSource(connectionPool); + + //return that data source. return dataSource; } catch (ClassNotFoundException e) { - throw new DatabaseCreationException - ("Database driver '" + driver + "' could not be found", e); + throw new DatabaseCreationException( + "Database driver '" + driver + "' could not be found", e); } } private DataSource createNewInternalDataSource(String dbName) throws DatabaseCreationException { - String newDatabaseConnectionURL = DERBY_PROTOCOL + - dbName + - DEFAULT_CREATE_CONNECTION_STRING; + String newDatabaseConnectionURL = DERBY_PROTOCOL + + dbName + + DEFAULT_CREATE_CONNECTION_STRING; return createNewDataSource(DERBY_DRIVER_NAME, newDatabaseConnectionURL, null, null); } @@ -163,10 +167,10 @@ Statement removeTables = dbConnection.createStatement(); while (allTableNames.next()) { - if (allTableNames.getString(SCHEMA_NAME_INDEX).indexOf(NONSYSTEM_SCHEMA_NAME) != -1) { + if (!hasSystemSchema(allTableNames.getString(SCHEMA_NAME_INDEX))) { String removeTableSQL = - "DROP TABLE " + - NONSYSTEM_SCHEMA_NAME + "." + allTableNames.getString(TABLE_NAME_INDEX); + "DROP TABLE " + + NONSYSTEM_SCHEMA_NAME + "." + allTableNames.getString(TABLE_NAME_INDEX); removeTables.addBatch(removeTableSQL); } } @@ -174,5 +178,7 @@ removeTables.executeBatch(); } - + private boolean hasSystemSchema(String tableSchemaName) { + return tableSchemaName.indexOf(NONSYSTEM_SCHEMA_NAME) == -1; + } } Deleted: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java 2009-12-21 21:30:24 UTC (rev 996) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java 2009-12-23 16:07:47 UTC (rev 997) @@ -1,30 +0,0 @@ -package org.cishell.reference.service.database; - -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.DataSource; - -import org.cishell.service.database.Database; - -public class ExternalDatabase implements Database { - - private DataSource dataSource; - - public ExternalDatabase(DataSource dataSource) { - this.dataSource = dataSource; - } - - public Connection getConnection() throws SQLException { - return dataSource.getConnection(); - } - - /* - * TODO: We could store the password from the beginning. - * Will want to discuss security implications here. - */ - public Connection getConnection(String username, String password) - throws SQLException { - return dataSource.getConnection(username, password); - } -} Copied: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java (from rev 993, trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java) =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java (rev 0) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java 2009-12-23 16:07:47 UTC (rev 997) @@ -0,0 +1,30 @@ +package org.cishell.reference.service.database; + +import java.sql.Connection; +import java.sql.SQLException; + +import javax.sql.DataSource; + +import org.cishell.service.database.Database; + +public class ExternalDatabase implements Database { + + private DataSource dataSource; + + public ExternalDatabase(DataSource dataSource) { + this.dataSource = dataSource; + } + + public Connection getConnection() throws SQLException { + return dataSource.getConnection(); + } + + /* + * TODO: We could store the password from the beginning. + * Will want to discuss security implications here. + */ + public Connection getConnection(String username, String password) + throws SQLException { + return dataSource.getConnection(username, password); + } +} Property changes on: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2009-12-21 21:30:24 UTC (rev 996) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2009-12-23 16:07:47 UTC (rev 997) @@ -10,11 +10,9 @@ public class InternalDerbyDatabase implements Database { - private String name; private DataSource dataSource; - public InternalDerbyDatabase(String name, DataSource dataSource) { - this.name = name; + public InternalDerbyDatabase(DataSource dataSource) { this.dataSource = dataSource; } @@ -25,8 +23,8 @@ public void shutdown() throws SQLException { String shutdownDatabaseCommand = - DerbyDatabaseService.DERBY_PROTOCOL + - DerbyDatabaseService.DEFAULT_SHUTDOWN_CONNECTION_STRING; + DerbyDatabaseService.DERBY_PROTOCOL + + DerbyDatabaseService.DEFAULT_SHUTDOWN_CONNECTION_STRING; DriverManager.getConnection(shutdownDatabaseCommand); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-12-21 21:30:31
|
Revision: 996 http://cishell.svn.sourceforge.net/cishell/?rev=996&view=rev Author: pataphil Date: 2009-12-21 21:30:24 +0000 (Mon, 21 Dec 2009) Log Message: ----------- * Added StringUtilities.validAndEquivalent() and StringUtilities.simpleMerge(). Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-18 22:50:57 UTC (rev 995) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-21 21:30:24 UTC (rev 996) @@ -175,4 +175,32 @@ return -1; } + + public static boolean validAndEquivalent(String string1, String string2) { + return (!isEmptyOrWhiteSpace(string1) && (string1.compareTo(string2) == 0)); + } + + public static boolean validAndEquivalentIgnoreCase(String string1, String string2) { + return (!isEmptyOrWhiteSpace(string1) && (string1.compareToIgnoreCase(string2) == 0)); + } + + // TODO: New Name. + public static String simpleMerge(String string1, String string2) { + if (!isEmptyOrWhiteSpace(string1)) { + if (!isEmptyOrWhiteSpace(string2)) { + if (string1.length() >= string2.length()) { + return string1; + } else { + return string2; + } + } else { + return string1; + } + } + else if (!isEmptyOrWhiteSpace(string2)) { + return string2; + } + + return string1; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-12-18 22:51:03
|
Revision: 995 http://cishell.svn.sourceforge.net/cishell/?rev=995&view=rev Author: pataphil Date: 2009-12-18 22:50:57 +0000 (Fri, 18 Dec 2009) Log Message: ----------- * Added StringUtilities.prefixIndex. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-17 20:26:50 UTC (rev 994) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-18 22:50:57 UTC (rev 995) @@ -161,4 +161,18 @@ cleanedWord.substring(1).toLowerCase(); } } + + public static int prefixIndex(String target, String[] prefixes) { + /* + * Look for the prefixes in reverse order (so a longer one will win out over a shorter one + * if they both have a beginning in common). + */ + for (int ii = (prefixes.length - 1); ii >= 0; ii--) { + if (target.startsWith(prefixes[ii])) { + return ii; + } + } + + return -1; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-12-17 20:27:00
|
Revision: 994 http://cishell.svn.sourceforge.net/cishell/?rev=994&view=rev Author: mwlinnem Date: 2009-12-17 20:26:50 +0000 (Thu, 17 Dec 2009) Log Message: ----------- Removed junit dependency, which should make this work. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF Modified: trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2009-12-17 20:09:00 UTC (rev 993) +++ trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2009-12-17 20:26:50 UTC (rev 994) @@ -20,4 +20,3 @@ org.osgi.service.log;version="1.3.0", org.osgi.util.tracker;version="1.3.3" Service-Component: OSGI-INF/component.xml -Require-Bundle: org.junit4 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-12-17 20:09:08
|
Revision: 993 http://cishell.svn.sourceforge.net/cishell/?rev=993&view=rev Author: mwlinnem Date: 2009-12-17 20:09:00 +0000 (Thu, 17 Dec 2009) Log Message: ----------- Changed to create entirely new databases (not just new data sources) for each new database datamanager item. Not compatible with previous version. Still in development, but uploading so Patrick can use it in his algorithm as is. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java trunk/core/org.cishell.service.database/META-INF/MANIFEST.MF trunk/core/org.cishell.service.database/src/org/cishell/service/database/DatabaseService.java Added Paths: ----------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java trunk/core/org.cishell.service.database/src/org/cishell/service/database/Database.java Removed Paths: ------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DataSourceWithIDImpl.java Modified: trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2009-12-16 17:21:31 UTC (rev 992) +++ trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2009-12-17 20:09:00 UTC (rev 993) @@ -13,7 +13,11 @@ org.apache.derby.jdbc, org.cishell.framework.algorithm;version="1.0.0", org.cishell.service.database, + org.eclipse.core.internal.runtime, org.osgi.framework;version="1.4.0", + org.osgi.service.cm;version="1.2.0", org.osgi.service.component;version="1.0.0", - org.osgi.service.log;version="1.3.0" + org.osgi.service.log;version="1.3.0", + org.osgi.util.tracker;version="1.3.3" Service-Component: OSGI-INF/component.xml +Require-Bundle: org.junit4 Deleted: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DataSourceWithIDImpl.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DataSourceWithIDImpl.java 2009-12-16 17:21:31 UTC (rev 992) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DataSourceWithIDImpl.java 2009-12-17 20:09:00 UTC (rev 993) @@ -1,79 +0,0 @@ -package org.cishell.reference.service.database; - -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.DataSource; - -import org.cishell.service.database.DataSourceWithID; - -public class DataSourceWithIDImpl implements DataSource, DataSourceWithID { - private static int idCounter = 0; - - private DataSource wrappedDataSource; - private int id; - - private static int generateNewID() { - int newID = idCounter; - - idCounter++; - - return newID; - } - - public DataSourceWithIDImpl(DataSource wrappedDataSource) { - this.wrappedDataSource = wrappedDataSource; - this.id = generateNewID(); - } - - /* (non-Javadoc) - * @see org.cishell.service.database.DataSourceWithIDI#getID() - */ - public int getID() { - return id; - } - - /* (non-Javadoc) - * @see org.cishell.service.database.DataSourceWithIDI#getConnection() - */ - public Connection getConnection() throws SQLException { - return this.wrappedDataSource.getConnection(); - } - - /* (non-Javadoc) - * @see org.cishell.service.database.DataSourceWithIDI#getConnection(java.lang.String, java.lang.String) - */ - public Connection getConnection(String username, String password) - throws SQLException { - return this.wrappedDataSource.getConnection(username, password); - } - - /* (non-Javadoc) - * @see org.cishell.service.database.DataSourceWithIDI#getLogWriter() - */ - public PrintWriter getLogWriter() throws SQLException { - return this.wrappedDataSource.getLogWriter(); - } - - /* (non-Javadoc) - * @see org.cishell.service.database.DataSourceWithIDI#setLogWriter(java.io.PrintWriter) - */ - public void setLogWriter(PrintWriter out) throws SQLException { - this.wrappedDataSource.setLogWriter(out); - } - - /* (non-Javadoc) - * @see org.cishell.service.database.DataSourceWithIDI#getLoginTimeout() - */ - public int getLoginTimeout() throws SQLException { - return this.wrappedDataSource.getLoginTimeout(); - } - - /* (non-Javadoc) - * @see org.cishell.service.database.DataSourceWithIDI#setLoginTimeout(int) - */ - public void setLoginTimeout(int seconds) throws SQLException { - this.wrappedDataSource.setLoginTimeout(seconds); - } -} \ No newline at end of file Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-16 17:21:31 UTC (rev 992) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-17 20:09:00 UTC (rev 993) @@ -2,11 +2,12 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; -import java.sql.DriverManager; import java.sql.ResultSet; -import java.sql.SQLException; import java.sql.Statement; +import java.util.ArrayList; import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; import javax.sql.DataSource; @@ -17,73 +18,57 @@ import org.apache.commons.pool.KeyedObjectPoolFactory; import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory; import org.apache.commons.pool.impl.GenericObjectPool; -import org.cishell.service.database.DataSourceWithID; +import org.cishell.service.database.Database; import org.cishell.service.database.DatabaseCreationException; import org.cishell.service.database.DatabaseService; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; - public class DerbyDatabaseService implements DatabaseService, BundleActivator { - /* - * Variables used to connect to the internal derby database - * - * TODO: Eventually support connecting databases other than derby, - * and connecting to databases other than our internal one - * (maybe not by modifying this class directly though). - */ - private static final String DERBY_DRIVER_NAME = + public static final String DERBY_DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver"; - private static final String DERBY_PROTOCOL = "jdbc:derby:"; - private static final String DEFAULT_CREATE_CONNECTION_STRING = ";create=true"; - private static final String DEFAULT_SHUTDOWN_CONNECTION_STRING =";shutdown=true"; - private static final String DEFAULT_DB_NAME = "cishell_database"; + public static final String DERBY_PROTOCOL = "jdbc:derby:"; + public static final String DEFAULT_CREATE_CONNECTION_STRING = ";create=true"; + public static final String DEFAULT_SHUTDOWN_CONNECTION_STRING =";shutdown=true"; //where the database exists on the filesystem (relative to the application root directory) private static final String DATABASE_DIRECTORY = "database/"; - //(new connections to the database will come from a pool of connections, improving performance) - private PoolingDataSource poolingDataSource = null; - //hold on to our service registration so we can unregister when this plugin stops. private ServiceRegistration databaseServiceRegistration; + private List internalDatabases = new ArrayList(); + public void start(BundleContext context) throws Exception { /* * Tell Derby to look for an existing database or create a new database - * in the default directory (within our application's directory) + * in the default directory (within our application's directory) */ System.setProperty("derby.system.home", DATABASE_DIRECTORY); - /* - * Make sure we don't have any leftover cruft in the db from previous sessions. - * This is our second chance, if the database wasn't properly cleaned out - * in the stop() method on application exit. - * TODO: If we ever implement some kind of persistence we may not want to do this so bluntly - */ - removeAllNonSystemDatabaseTables(); - //allow the database service to be found by other services/plugins databaseServiceRegistration = context.registerService (DatabaseService.class.getName(), this, new Hashtable()); - } public void stop(BundleContext context) { //disallow the database service to be found by other services/plugins this.databaseServiceRegistration.unregister(); - //try to clean out the database and shut it down. + //try to clean out the databases and shut them down. try { - removeAllNonSystemDatabaseTables(); - String shutdownDatabaseCommand = - DERBY_PROTOCOL + DEFAULT_SHUTDOWN_CONNECTION_STRING; - DriverManager.getConnection(shutdownDatabaseCommand); + + + for (Iterator it = internalDatabases.iterator(); it.hasNext();) { + InternalDerbyDatabase activeDatabase = (InternalDerbyDatabase) it.next(); + Connection activeDatabaseConnection = activeDatabase.getConnection(); + removeAllNonSystemDatabaseTables(activeDatabaseConnection); + activeDatabase.shutdown(); + } } catch (Exception e) { String message = "An unexpected exception occurred while shutting down the internal database." + @@ -92,22 +77,86 @@ throw new RuntimeException(message, e); } } + - //Return a link to a "database" that cannot interfere with other "databases" in the system. - //TODO: May need to refactor to improve the terminology used surrounding this functionality. - public DataSourceWithID createDatabase() throws DatabaseCreationException { - return new DataSourceWithIDImpl(getDataSource()); + private static final String DB_NAME_PREFIX = "cishell_database"; + private static int id = 0; + + public synchronized Database createNewDatabase() throws DatabaseCreationException { + try { + //connect to and create a 'new' database + String databaseName = DB_NAME_PREFIX + id; + Database db = new InternalDerbyDatabase(databaseName, createNewInternalDataSource(databaseName)); + + //if this database existed on disk from a previous session, clean it to be like new + removeAllNonSystemDatabaseTables(db.getConnection()); + + //keep track of our new database for this CIShell session + internalDatabases.add(db); + + id++; + return db; + } catch (Exception e) { + throw new DatabaseCreationException(e); + } } + public Database connectToExistingDatabase(String driver, String url) + throws DatabaseCreationException { + return connectToExistingDatabase(driver, url, null, null); + } + public Database connectToExistingDatabase( + String driver, String url, String username, String password) + throws DatabaseCreationException { + DataSource dataSource = + createNewDataSource(driver, url, username, password); + //TODO: change Database to support non-derby urls and whatnot + Database db = new ExternalDatabase(dataSource); + //(assuming we don't need to keep track of these databases, as we will not close them on shutdown) + return db; + } + + + + //***---UTILITIES---*** + + private DataSource createNewDataSource( + String driver, String url, String username, String password) + throws DatabaseCreationException { + try { + //Load the database driver + Class.forName(driver); + + ConnectionFactory connectionFactory = new DriverManagerConnectionFactory + (url, username, password); + GenericObjectPool connectionPool = new GenericObjectPool(); + KeyedObjectPoolFactory stmtPool = new GenericKeyedObjectPoolFactory(null); + //(side-effects) + new PoolableConnectionFactory(connectionFactory, connectionPool, stmtPool, null, false, true); + //(creating the data source this way is probably overkill for our current purposes, + //(but I don't imagine it does much harm either). + DataSource dataSource = new PoolingDataSource(connectionPool); + return dataSource; + } catch (ClassNotFoundException e) { + throw new DatabaseCreationException + ("Database driver '" + driver + "' could not be found", e); + } + } + + private DataSource createNewInternalDataSource(String dbName) + throws DatabaseCreationException { + String newDatabaseConnectionURL = DERBY_PROTOCOL + + dbName + + DEFAULT_CREATE_CONNECTION_STRING; + return createNewDataSource(DERBY_DRIVER_NAME, newDatabaseConnectionURL, null, null); + } + private static final int SCHEMA_NAME_INDEX = 2; private static final int TABLE_NAME_INDEX = 3; private static final String NONSYSTEM_SCHEMA_NAME = "APP"; - private void removeAllNonSystemDatabaseTables() throws Exception { - - DataSource db = getDataSource(); - Connection dbConnection = db.getConnection(); + private void removeAllNonSystemDatabaseTables(Connection dbConnection) throws Exception { DatabaseMetaData dbMetadata = dbConnection.getMetaData(); ResultSet allTableNames = dbMetadata.getTables(null, null, null, null); @@ -124,45 +173,6 @@ removeTables.executeBatch(); } - - //TODO: It could be that we should give everyone different datasources instead of the same one - private PoolingDataSource getDataSource() throws DatabaseCreationException - { - if (this.poolingDataSource == null) { initializePoolingDataSource(); }; - return poolingDataSource; - } - //lazy-load the pooling data source (implicitly creates the initial database connection) - //TODO: Make it more clear where database connection is initially established - private void initializePoolingDataSource() throws DatabaseCreationException { - if (this.poolingDataSource != null) { - return; - } - - try { - //Load the database driver - Class.forName(DERBY_DRIVER_NAME); - - /* - * TODO:We can use this later to check acceptsUrl for better error reporting. - * Driver jdbcDriver = (Driver) Class.forName(driver).newInstance(); - */ - String newDatabaseConnectionURL = DERBY_PROTOCOL + - DEFAULT_DB_NAME + - DEFAULT_CREATE_CONNECTION_STRING; - - ConnectionFactory connectionFactory = new DriverManagerConnectionFactory - (newDatabaseConnectionURL, null, null); - GenericObjectPool connectionPool = new GenericObjectPool(); - KeyedObjectPoolFactory stmtPool = new GenericKeyedObjectPoolFactory(null); - //(side-effects the connection-pool so it gets its connections from the connection factory (I think)) - new PoolableConnectionFactory(connectionFactory, connectionPool, stmtPool, null, false, true); - this.poolingDataSource = new PoolingDataSource(connectionPool); - } - catch (ClassNotFoundException e) { - throw new DatabaseCreationException - ("Database driver '" + DERBY_DRIVER_NAME + "' could not be found", e); - } - } } Added: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java (rev 0) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java 2009-12-17 20:09:00 UTC (rev 993) @@ -0,0 +1,30 @@ +package org.cishell.reference.service.database; + +import java.sql.Connection; +import java.sql.SQLException; + +import javax.sql.DataSource; + +import org.cishell.service.database.Database; + +public class ExternalDatabase implements Database { + + private DataSource dataSource; + + public ExternalDatabase(DataSource dataSource) { + this.dataSource = dataSource; + } + + public Connection getConnection() throws SQLException { + return dataSource.getConnection(); + } + + /* + * TODO: We could store the password from the beginning. + * Will want to discuss security implications here. + */ + public Connection getConnection(String username, String password) + throws SQLException { + return dataSource.getConnection(username, password); + } +} Added: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java (rev 0) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2009-12-17 20:09:00 UTC (rev 993) @@ -0,0 +1,34 @@ +package org.cishell.reference.service.database; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +import javax.sql.DataSource; + +import org.cishell.service.database.Database; + +public class InternalDerbyDatabase implements Database { + + private String name; + private DataSource dataSource; + + public InternalDerbyDatabase(String name, DataSource dataSource) { + this.name = name; + this.dataSource = dataSource; + } + + + public Connection getConnection() throws SQLException { + return this.dataSource.getConnection(); + } + + public void shutdown() throws SQLException { + String shutdownDatabaseCommand = + DerbyDatabaseService.DERBY_PROTOCOL + + DerbyDatabaseService.DEFAULT_SHUTDOWN_CONNECTION_STRING; + DriverManager.getConnection(shutdownDatabaseCommand); + + + } +} Modified: trunk/core/org.cishell.service.database/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.service.database/META-INF/MANIFEST.MF 2009-12-16 17:21:31 UTC (rev 992) +++ trunk/core/org.cishell.service.database/META-INF/MANIFEST.MF 2009-12-17 20:09:00 UTC (rev 993) @@ -5,3 +5,4 @@ Bundle-Version: 1.0.0 Bundle-RequiredExecutionEnvironment: J2SE-1.4 Export-Package: org.cishell.service.database +Import-Package: org.apache.commons.dbcp Added: trunk/core/org.cishell.service.database/src/org/cishell/service/database/Database.java =================================================================== --- trunk/core/org.cishell.service.database/src/org/cishell/service/database/Database.java (rev 0) +++ trunk/core/org.cishell.service.database/src/org/cishell/service/database/Database.java 2009-12-17 20:09:00 UTC (rev 993) @@ -0,0 +1,10 @@ +package org.cishell.service.database; + +import java.sql.Connection; +import java.sql.SQLException; + +import org.apache.commons.dbcp.ConnectionFactory; + +public interface Database { + public Connection getConnection() throws SQLException; +} \ No newline at end of file Modified: trunk/core/org.cishell.service.database/src/org/cishell/service/database/DatabaseService.java =================================================================== --- trunk/core/org.cishell.service.database/src/org/cishell/service/database/DatabaseService.java 2009-12-16 17:21:31 UTC (rev 992) +++ trunk/core/org.cishell.service.database/src/org/cishell/service/database/DatabaseService.java 2009-12-17 20:09:00 UTC (rev 993) @@ -1,5 +1,10 @@ package org.cishell.service.database; public interface DatabaseService { - public DataSourceWithID createDatabase() throws DatabaseCreationException; + public Database createNewDatabase() throws DatabaseCreationException; + public Database connectToExistingDatabase(String driver, String url) + throws DatabaseCreationException; + public Database connectToExistingDatabase( + String driver, String url, String username, String password) + throws DatabaseCreationException; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-12-16 17:21:38
|
Revision: 992 http://cishell.svn.sourceforge.net/cishell/?rev=992&view=rev Author: pataphil Date: 2009-12-16 17:21:31 +0000 (Wed, 16 Dec 2009) Log Message: ----------- * Added StringUtilities.simpleCleanStrings and StringUtilities.toSentenceCase. * Reviewed by Chintan. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-14 19:22:36 UTC (rev 991) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-16 17:21:31 UTC (rev 992) @@ -139,4 +139,26 @@ return guaranteedToNotBeNull.trim(); } + + public static final String[] simpleCleanStrings(String[] strings) { + List cleanedStrings = new ArrayList(); + + for (int ii = 0; ii < strings.length; ii ++) { + cleanedStrings.add(StringUtilities.simpleClean(strings[ii])); + } + + return (String[])cleanedStrings.toArray(new String[0]); + } + + public static String toSentenceCase(String word) { + String cleanedWord = simpleClean(word); + + if (cleanedWord.length() == 0) { + return ""; + } else { + return + Character.toUpperCase(cleanedWord.charAt(0)) + + cleanedWord.substring(1).toLowerCase(); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-12-14 19:22:46
|
Revision: 991 http://cishell.svn.sourceforge.net/cishell/?rev=991&view=rev Author: pataphil Date: 2009-12-14 19:22:36 +0000 (Mon, 14 Dec 2009) Log Message: ----------- * Added StringUtilities.emtpyStringIfNull() and StringUtilities.simpleClean(). * Reviewed by Chintan. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-11 18:08:27 UTC (rev 990) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2009-12-14 19:22:36 UTC (rev 991) @@ -125,4 +125,18 @@ return stringInProgress.toString(); } } + + public static String emptyStringIfNull(Object object) { + if (object == null) { + return ""; + } else { + return object.toString(); + } + } + + public static String simpleClean(String string) { + String guaranteedToNotBeNull = emptyStringIfNull(string); + + return guaranteedToNotBeNull.trim(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-12-11 18:08:34
|
Revision: 990 http://cishell.svn.sourceforge.net/cishell/?rev=990&view=rev Author: pataphil Date: 2009-12-11 18:08:27 +0000 (Fri, 11 Dec 2009) Log Message: ----------- * Moved SetMap out of edu.iu.nwb.converter.prefuseisi to org.cishell.utilities. * Reviewed by Chintan. Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/SetMap.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/SetMap.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/SetMap.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/SetMap.java 2009-12-11 18:08:27 UTC (rev 990) @@ -0,0 +1,30 @@ +package org.cishell.utilities; + +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Map; +import java.util.Set; + +public class SetMap { + private Map map = new Hashtable(); + + public void put(Object key, Object value) { + Set valueSet = (Set) this.map.get(key); + if (valueSet == null) { + valueSet = new HashSet(); + } + + valueSet.add(value); + + this.map.put(key, valueSet); + } + + public Set keySet() { + return this.map.keySet(); + } + + public Set get(Object key) { + return (Set) this.map.get(key); + } +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-12-04 23:14:10
|
Revision: 989 http://cishell.svn.sourceforge.net/cishell/?rev=989&view=rev Author: pataphil Date: 2009-12-04 23:14:01 +0000 (Fri, 04 Dec 2009) Log Message: ----------- * Did a fair amount of code cleanup. * Algorithms can now assign keyboard shortcuts to their corresponding menu entries via the "shortcut" property (in their properties files). * Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/ApplicationActionBarAdvisor.java trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmProperty.java Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2009-12-04 23:11:02 UTC (rev 988) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2009-12-04 23:14:01 UTC (rev 989) @@ -68,49 +68,34 @@ import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; -/** - * - * @author Bruce Herr (bh...@bh...) - */ -public abstract class AbstractDataManagerView extends ViewPart implements - DataManagerListener, BundleListener { +public abstract class AbstractDataManagerView + extends ViewPart + implements DataManagerListener, BundleListener { private String brandPluginID; - private DataManagerService manager; - private TreeViewer viewer; - private TreeEditor editor; - + // TODO: Finish cleaning this file up. private Text newEditor; - private DataGUIItem rootItem; - - // flag to notify if a tree item is currently being updated so there - // isnt a conflict among various listeners + /* + * Flag to notify if a tree item is currently being updated so there isnt a conflict among + * various listeners. + */ private boolean updatingTreeItem; - private Tree tree; - private Menu menu; - private Map dataToDataGUIItemMap; - private AlgorithmFactory saveFactory; private AlgorithmFactory viewFactory; private AlgorithmFactory viewWithFactory; - - private DiscardListener discardListener; - private SaveListener saveListener; private ViewListener viewListener; private ViewWithListener viewWithListener; private LogService log; public AbstractDataManagerView(String brandPluginID) { - - this.brandPluginID = brandPluginID; dataToDataGUIItemMap = new HashMap(); @@ -124,9 +109,12 @@ } } - private String getItemID(ServiceReference ref) { - return ref.getProperty("PID:" + Constants.SERVICE_PID) + "-SID:" + - ref.getProperty(Constants.SERVICE_ID); + private String getItemID(ServiceReference serviceReference) { + return serviceReference.getProperty( + "PID:" + + Constants.SERVICE_PID) + + "-SID:" + + serviceReference.getProperty(Constants.SERVICE_ID); } @@ -134,19 +122,18 @@ * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { - // Label label = new Label(parent, SWT.NONE); // label.setText("Data Manager"); - viewer = new TreeViewer(parent); - viewer.setContentProvider(new DataTreeContentProvider()); - viewer.setLabelProvider(new DataTreeLabelProvider()); + this.viewer = new TreeViewer(parent); + this.viewer.setContentProvider(new DataTreeContentProvider()); + this.viewer.setLabelProvider(new DataTreeLabelProvider()); rootItem = new DataGUIItem(null, null, this.brandPluginID); - viewer.setInput(rootItem); - viewer.expandAll(); + this.viewer.setInput(rootItem); + this.viewer.expandAll(); // grab the tree and add the appropriate listeners - tree = viewer.getTree(); + tree = this.viewer.getTree(); tree.addSelectionListener(new DatamodelSelectionListener()); tree.addMouseListener(new ContextMenuListener()); @@ -183,22 +170,21 @@ discardItem.addListener(SWT.Selection, discardListener); tree.setMenu(menu); - // allow cells to be edited on double click or when pressing enter on - // them - editor = new TreeEditor(tree); - editor.horizontalAlignment = SWT.LEFT; - editor.grabHorizontal = true; - editor.minimumWidth = 50; + // Allow cells to be edited on double click or when pressing enter on them. + this.editor = new TreeEditor(tree); + this.editor.horizontalAlignment = SWT.LEFT; + this.editor.grabHorizontal = true; + this.editor.minimumWidth = 50; // listen to OSGi for models being added by plugins - if (manager != null) { - manager.addDataManagerListener(this); - } - else { + if (this.manager != null) { + this.manager.addDataManagerListener(this); + } else { Activator.getBundleContext().addBundleListener(this); - manager = Activator.getDataManagerService(); - if (manager != null) { - manager.addDataManagerListener(this); + this.manager = Activator.getDataManagerService(); + + if (this.manager != null) { + this.manager.addDataManagerListener(this); } } @@ -207,9 +193,10 @@ public void bundleChanged(BundleEvent event) { if (event.getType() == BundleEvent.STARTED) { - manager = Activator.getDataManagerService(); - if (manager != null) { - manager.addDataManagerListener(this); + this.manager = Activator.getDataManagerService(); + + if (this.manager != null) { + this.manager.addDataManagerListener(this); } } } @@ -218,7 +205,7 @@ * @see org.eclipse.ui.part.WorkbenchPart#setFocus() */ public void setFocus() { - viewer.getControl().setFocus(); + this.viewer.getControl().setFocus(); } public void dataAdded(final Data newData, String label) { @@ -246,12 +233,12 @@ public void run() { if (!tree.isDisposed()) { // update the TreeView - viewer.refresh(); + AbstractDataManagerView.this.viewer.refresh(); // context menu may need to have options enabled/disabled // based on the new selection updateContextMenu(newData); // update the global selection - viewer.expandToLevel(newItem, 0); + AbstractDataManagerView.this.viewer.expandToLevel(newItem, 0); manager.setSelectedData((Data[]) selection.toArray(new Data[0])); } } @@ -390,7 +377,7 @@ modelArray[i] = model; } - manager.setSelectedData(modelArray); + AbstractDataManagerView.this.manager.setSelectedData(modelArray); } } @@ -401,7 +388,7 @@ */ private void handleInput() { // Clean up any previous editor control - Control oldEditor = editor.getEditor(); + Control oldEditor = this.editor.getEditor(); if (oldEditor != null) { oldEditor.dispose(); @@ -428,7 +415,8 @@ public void focusLost(FocusEvent e) { if (!updatingTreeItem) { //updateText(newEditor.getText(), item); - manager.setLabel(((DataGUIItem)item.getData()).getModel(), newEditor.getText()); + AbstractDataManagerView.this.manager.setLabel( + ((DataGUIItem)item.getData()).getModel(), newEditor.getText()); // FELIX. This is not > stupidness. } } @@ -446,7 +434,7 @@ }); newEditor.selectAll(); newEditor.setFocus(); - editor.setEditor(newEditor, item); + this.editor.setEditor(newEditor, item); } /* @@ -460,7 +448,7 @@ newLabel = newLabel.substring(1); - editor.getItem().setText(newLabel); + this.editor.getItem().setText(newLabel); DataGUIItem treeItem = (DataGUIItem) item.getData(); Data model = treeItem.getModel(); @@ -581,11 +569,11 @@ } dataToDataGUIItemMap.remove(item.getModel()); - manager.removeData(item.getModel()); + AbstractDataManagerView.this.manager.removeData(item.getModel()); } - manager.setSelectedData(new Data[0]); - viewer.refresh(); + AbstractDataManagerView.this.manager.setSelectedData(new Data[0]); + AbstractDataManagerView.this.viewer.refresh(); } } @@ -638,7 +626,7 @@ public void setSelection(ISelection selection) { if (selection != this.selection) { this.selection = selection; - viewer.refresh(true); + AbstractDataManagerView.this.viewer.refresh(true); if (selection != null && selection instanceof IStructuredSelection) { @@ -652,7 +640,7 @@ TreeItem result = getTreeItem((Data) next, tree .getItems()); newTreeSelection[i] = result; - viewer.expandToLevel( + AbstractDataManagerView.this.viewer.expandToLevel( dataToDataGUIItemMap.get(next), 0); } i++; Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2009-12-04 23:11:02 UTC (rev 988) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2009-12-04 23:14:01 UTC (rev 989) @@ -40,23 +40,13 @@ protected Data[] originalData; protected Converter[][] converters; - public AlgorithmAction(ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { - this.ref = ref; - this.ciContext = ciContext; - this.bContext = bContext; - - setText((String)ref.getProperty(LABEL)); - setToolTipText((String)ref.getProperty(AlgorithmProperty.DESCRIPTION)); - - DataManagerService dataManager = (DataManagerService) - bContext.getService(bContext.getServiceReference( - DataManagerService.class.getName())); - - dataManager.addDataManagerListener(this); - dataSelected(dataManager.getSelectedData()); + public AlgorithmAction( + ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { + this((String)ref.getProperty(LABEL), ref, bContext, ciContext); } - public AlgorithmAction(String label, ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { + public AlgorithmAction( + String label, ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { this.ref = ref; this.ciContext = ciContext; this.bContext = bContext; @@ -80,48 +70,68 @@ SchedulerService scheduler = (SchedulerService) getService(SchedulerService.class); scheduler.schedule(algorithm, ref); - } catch (Throwable e) { - //Just in case an uncaught exception occurs. Eclipse will swallow errors thrown here... - e.printStackTrace(); + } catch (Throwable exception) { + // Just in case an uncaught exception occurs. Eclipse will swallow errors thrown here. + exception.printStackTrace(); } } private void printAlgorithmInformation(ServiceReference ref, CIShellContext ciContext) { - //adjust to log the whole acknowledgement in one block + // Adjust to log the whole acknowledgement in one block. LogService logger = (LogService) ciContext.getService(LogService.class.getName()); StringBuffer acknowledgement = new StringBuffer(); String label = (String)ref.getProperty(LABEL); - if (label != null){ - acknowledgement.append("..........\n"+label+" was selected.\n"); + + if (label != null) { + acknowledgement.append("..........\n" + label + " was selected.\n"); } + String authors = (String)ref.getProperty(AUTHORS); - if (authors != null) - acknowledgement.append("Author(s): "+authors+"\n"); + + if (authors != null) { + acknowledgement.append("Author(s): " + authors + "\n"); + } + String implementers = (String)ref.getProperty(IMPLEMENTERS); - if (implementers != null) - acknowledgement.append("Implementer(s): "+implementers+"\n"); + + if (implementers != null) { + acknowledgement.append("Implementer(s): " + implementers + "\n"); + } + String integrators = (String)ref.getProperty(INTEGRATORS); - if (integrators != null) - acknowledgement.append("Integrator(s): "+integrators+"\n"); + + if (integrators != null) { + acknowledgement.append("Integrator(s): " + integrators + "\n"); + } + String reference = (String)ref.getProperty(REFERENCE); String reference_url = (String)ref.getProperty(REFERENCE_URL); - if (reference != null && reference_url != null ) - acknowledgement.append("Reference: "+reference+ - " ("+reference_url+")\n"); - else if (reference != null && reference_url == null ) - acknowledgement.append("Reference: "+reference+"\n"); + + if ((reference != null) && (reference_url != null)) { + acknowledgement.append( + "Reference: " + reference + " (" + reference_url + ")\n"); + } else if ((reference != null) && (reference_url == null)) { + acknowledgement.append("Reference: " + reference + "\n"); + } + String docu = (String)ref.getProperty(DOCUMENTATION_URL); - if (docu != null) - acknowledgement.append("Documentation: "+docu+"\n"); - if(acknowledgement.length()>1) + + if (docu != null) { + acknowledgement.append("Documentation: " + docu + "\n"); + } + + if (acknowledgement.length() > 1) { logger.log(LogService.LOG_INFO, acknowledgement.toString()); + } } private String[] separateInData(String inDataString) { String[] inData = ("" + inDataString).split(","); - for(int ii = 0; ii < inData.length; ii++) { + + for (int ii = 0; ii < inData.length; ii++) { inData[ii] = inData[ii].trim(); } + return inData; } Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2009-12-04 23:11:02 UTC (rev 988) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2009-12-04 23:14:01 UTC (rev 989) @@ -13,9 +13,7 @@ * ***************************************************************************/ package org.cishell.reference.gui.menumanager.menu; -import java.io.File; import java.io.IOException; -import java.net.URISyntaxException; import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -55,243 +53,297 @@ public class MenuAdapter implements AlgorithmProperty { - private IMenuManager menuBar; + public static final String DEFAULT_MENU_FILE_NAME = "default_menu.xml"; + + // Tags in DEFAULT_MENU_FILE_NAME. + public static final String TAG_TOP_MENU = "top_menu"; + public static final String TAG_MENU = "menu"; + public static final String TYPE_ATTRIBUTE = "type"; + public static final String NAME_ATTRIBUTE = "name"; + public static final String PID_ATTRIBUTE = "pid"; + public static final String PRESERVED_GROUP = "group"; + public static final String PRESERVED_BREAK = "break"; + public static final String PRESERVED_EXIT = "Exit"; + public static final String PRESERVED_SERVICE_PID = "service.pid"; + public static final String PRESERVED = "preserved"; + + private IMenuManager menuManager; private Shell shell; - private BundleContext bContext; - private CIShellContext ciContext; - private Map algorithmToItemMap; - private Map itemToParentMap; - private ContextListener listener; - private IWorkbenchWindow window; - + private BundleContext bundleContext; + private CIShellContext ciShellContext; + private Map algorithmsToItems; + private Map itemsToParents; + private ContextListener contextListener; + private IWorkbenchWindow workbenchWindow; + private LogService logger; /* - * This map holds a pid as a key and the corresponding - * ServiceReference as a value. It is built when - * preprocessServiceBundles() is invoked. Then the entries - * are gradually removed when the pids are specified in - * the defaul_menu.xml. If any entries are left, in - * processLeftServiceBundles(), those plug-ins that have - * specified the menu_path and label but are not listed in - * default_menu.xml will be added on to the menu. + * This map holds a pid as a key and the corresponding ServiceReference as a value. + * It is built when preprocessServiceBundles() is invoked. + * Then the entries are gradually removed when the pids are specified in + * DEFAULT_MENU_FILE_NAME. + * If any entries are left, in processLeftServiceBundles(), those plug-ins that have specified + * the menu_path and label but are not listed in DEFAULT_MENU_FILE_NAME will be added on to + * the menu. */ - private Map pidToServiceReferenceMap; + private Map pidsToServiceReferences; /* - * This is the exactly same copy of pidToServiceReferenceMap. - * Since some plug-ins could display on menu more than once, it - * provides a map between a pid and a ref while in pidToServiceReferenceMap - * that pid has been removed. + * This is the exactly same copy of pidsToServiceReferences. + * Since some plug-ins could display on menu more than once, it provides a map between a pid + * and a ref while in pidsToServiceReferences that pid has been removed. */ - private Map pidToServiceReferenceMapCopy; - private Document dom; - private static String DEFAULT_MENU_FILE_NAME = "default_menu.xml"; - - /* - * The following section specify the tags in the default_menu.xml - */ - private static String TAG_TOP_MENU = "top_menu"; - private static String TAG_MENU = "menu"; - private static String ATTR_TYPE = "type"; - private static String ATTR_NAME = "name"; - private static String ATTR_PID = "pid"; - private static String PRESERVED_GROUP = "group"; - private static String PRESERVED_BREAK = "break"; - private static String PRESERVED_EXIT = "Exit"; - private static String PRESERVED_SERVICE_PID="service.pid"; - private static String PRESERVED = "preserved"; - + private Map pidsToServiceReferencesCopy; + private Document documentObjectModel; + private Runnable updateAction = new Runnable() { + public void run() { + MenuAdapter.this.menuManager.updateAll(true); + } + }; - - public MenuAdapter(IMenuManager menu, Shell shell, - BundleContext bContext,CIShellContext ciContext, - IWorkbenchWindow window) { - //basic initialization - this.menuBar = menu; + private Runnable stopAction = new Runnable() { + public void run() { + String[] algorithmKeys = + (String[])MenuAdapter.this.algorithmsToItems.keySet().toArray(new String[]{}); + + for (int ii = 0; ii < algorithmKeys.length; ii++) { + Action item = (Action)algorithmsToItems.get(algorithmKeys[ii]); + IMenuManager targetMenu = (IMenuManager)MenuAdapter.this.itemsToParents.get(item); + + targetMenu.remove(item.getId()); + MenuAdapter.this.algorithmsToItems.remove(algorithmKeys[ii]); + MenuAdapter.this.itemsToParents.remove(item); + } + } + }; + + public MenuAdapter( + IMenuManager menuManager, + Shell shell, + BundleContext bundleContext, + CIShellContext ciShellContext, + IWorkbenchWindow workbenchWindow) { + this.menuManager = menuManager; this.shell = shell; - this.bContext = bContext; - this.ciContext = ciContext; - this.window = window; - - this.algorithmToItemMap = new HashMap(); - this.itemToParentMap = new HashMap(); - - pidToServiceReferenceMap = new HashMap(); - pidToServiceReferenceMapCopy = new HashMap(); - - //appears to add a listener which updates the menu item whenever a - //corresponding change occurs in the bundle (registers, unregisters, etc...) - String filter = "(" + Constants.OBJECTCLASS + - "=" + AlgorithmFactory.class.getName() + ")"; - listener = new ContextListener(); - - + this.bundleContext = bundleContext; + this.ciShellContext = ciShellContext; + this.workbenchWindow = workbenchWindow; + this.algorithmsToItems = new HashMap(); + this.itemsToParents = new HashMap(); + this.pidsToServiceReferences = new HashMap(); + this.pidsToServiceReferencesCopy = new HashMap(); + this.logger = (LogService)this.ciShellContext.getService(LogService.class.getName()); + + /* + * The intention of this clearShortcuts was to programmatically clear all of the + * bound shortcuts, so any found in our own plugins wouldn't have conflicts. + * Doing this doesn't immediately seem very possible, though there may be some promise in + * "redirecting" the actions taken by the shortcuts. + * (See: http://dev.eclipse.org/newslists/news.eclipse.platform/msg79882.html ) + * As a note, the keyboard shortcuts are actually called accelerator key codes, and the + * machinery that makes them work is very deeply ingrained in Eclipse. + * The difficulties I faced with trying to clear already-bound shortcuts has led me to + * suspect three possible things: + * We may be "abusing" Eclipse by using it as the foundation for our own applications. + * There may be a way to customize/configure (or interface with) the culprit plugin + * that's binding the shortcuts before us (org.eclipse.ui.workbench). This seems to be + * highly-likely, and more research on the matter can probably be justified at + * some point. + * The intended way TO work around the shortcuts already being bound is to redirect the + * actions taken by them, as mentioned above. + * Either way, to get these shortcuts working, I'm just going to use non-standard key + * combinations. + */ + //clearShortcuts(); + + /* + * Appears to add a context listener which updates the menu item whenever a corresponding + * change occurs in the bundle (registers, unregisters, etc...). + */ + String filter = "(" + Constants.OBJECTCLASS + "=" + AlgorithmFactory.class.getName() + ")"; + this.contextListener = new ContextListener(); + try { - - bContext.addServiceListener(listener, filter); + bundleContext.addServiceListener(this.contextListener, filter); preprocessServiceBundles(); - String app_location = System.getProperty("osgi.configuration.area"); + String applicationLocation = System.getProperty("osgi.configuration.area"); - //Comments below refer to problems with earlier versions of this document. - //Keeping these around for now, as well as the system.out.printlns, - //until we are sure that the current fix works. + /* + * Comments below refer to problems with earlier versions of this document. + * Keeping these around for now, as well as the system.out.printlns, until we are sure + * that the current fix works. + */ /* - * This is a temporary fix. A bit complex to explain the observation - * I got so far. On Windows XP - * app_location = file:/C:/Documents and Settings/huangb/Desktop/ - * nwb-sept4/nwb/configuration/ + * This is a temporary fix. A bit complex to explain the observation I got so far. + * On Windows XP, + * app_location = + * file:/C:/Documents and Settings/huangb/Desktop/nwb-sept4/nwb/configuration/ * If I didn't trim "file:/", on some windows machines - * new File(fileFullpath).exists() will return false, and - * initializaMenu() will be invoked. When initializaMenu() is invoked, - * not all required top menus will show up. So either Bruce code - * or Tim's fix has some problems. Can not append top menu such as - * Tools-->Scheduler if Tools is not specified in the XML - * If pass trimed file path C:/Documents and Settings/huangb/Desktop/ - * nwb-sept4/nwb/configuration/ to createMenuFromXML, on some machines, - * URL = C:/Documents and Settings/huangb/Desktop/nwb-sept4/nwb/configuration/ - * is a bad one, and can not create a document builder instance and the - * DOM representation of the XML file. + * new File(fileFullpath).exists() + * will return false, and initializaMenu() will be invoked. + * When initializaMenu() is invoked, not all required top menus will show up. + * So either Bruce code or Tim's fix has some problems. Can not append top menu such as + * Tools-->Scheduler if Tools is not specified in the XML. + * If pass trimmed file path + * C:/Documents and Settings/huangb/Desktop/nwb-sept4/nwb/configuration/ + * to createMenuFromXML, on some machines, + * URL = C:/Documents and Settings/huangb/Desktop/nwb-sept4/nwb/configuration/ + * is a bad one, and can not create a document builder instance and the + * DOM representation of the XML file. * * This piece of code needs to be reviewed and refactored!!! */ - //Better to use System.err, since it prints the stream immediately instead of storing it in a buffer which might be lost if there is a crash. - System.err.println(">>>app_location = "+app_location); - String fileFullPath = app_location + DEFAULT_MENU_FILE_NAME; - System.err.println(">>>fileFullPath = " + fileFullPath); + /* + * Better to use System.err, since it prints the stream immediately instead of storing + * it in a buffer which might be lost if there is a crash. + */ + String fileFullPath = applicationLocation + DEFAULT_MENU_FILE_NAME; URL configurationDirectoryURL = new URL(fileFullPath); - System.err.println(">>>URL = " + configurationDirectoryURL.toString()); + try { configurationDirectoryURL.getContent(); - System.out.println(">>>config.ini Exists!"); + //System.out.println(">>>config.ini Exists!"); createMenuFromXML(fileFullPath); processLeftServiceBundles(); - } catch (IOException e) { - e.printStackTrace(); - System.err.println("config.ini does not exist... Reverting to backup plan"); + } catch (IOException ioException) { + ioException.printStackTrace(); + //System.err.println("config.ini does not exist... Reverting to backup plan"); initializeMenu(); } - Display.getDefault().asyncExec(updateAction); - - } catch (InvalidSyntaxException e) { - getLog().log(LogService.LOG_DEBUG, "Invalid Syntax", e); - } catch (Throwable e) { - //Should catch absolutely everything catchable. Will hopefully reveal the error coming out of the URI constructor. - //No time to test today, just commiting this for testing later. - e.printStackTrace(); + + Display.getDefault().asyncExec(this.updateAction); + } catch (InvalidSyntaxException invalidSyntaxException) { + // TODO: Improve this error message. "Invalid Syntax" is terrible! + this.logger.log(LogService.LOG_DEBUG, "Invalid Syntax", invalidSyntaxException); + } catch (Throwable exception) { + /* + * TODO: Improve this. + * Should catch absolutely everything catchable. Will hopefully reveal the error coming + * out of the URI constructor. + * No time to test today, just commiting this for testing later. + */ + exception.printStackTrace(); } } /* - * This method scans all service bundles. If a bundle specifies - * menu_path and label, get service.pid of this bundle (key), let the service - * reference as the value, and put key/value pair - * to pidToServiceReferenceMap for further processing. - * + * This method scans all service bundles. If a bundle specifies menu_path and label, + * get service.pid of this bundle (key), let the service reference as the value, and put + * key/value pair to pidsToServiceReferences for further processing. */ - private void preprocessServiceBundles() throws InvalidSyntaxException{ - ServiceReference[] refs = bContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), null); - if (refs != null){ - for (int i=0; i < refs.length; i++) { - String path = (String)refs[i].getProperty(MENU_PATH); - String label = (String)refs[i].getProperty(LABEL); - if (path == null){ + private void preprocessServiceBundles() throws InvalidSyntaxException { + ServiceReference[] serviceReferences = + this.bundleContext.getAllServiceReferences(AlgorithmFactory.class.getName(), null); + + if (serviceReferences != null){ + for (int ii = 0; ii < serviceReferences.length; ii++) { + String path = (String)serviceReferences[ii].getProperty(MENU_PATH); + + if (path == null) { continue; + } else { + String pid = (String)serviceReferences[ii].getProperty(PRESERVED_SERVICE_PID); + pidsToServiceReferences.put(pid.toLowerCase().trim(), serviceReferences[ii]); + pidsToServiceReferencesCopy.put( + pid.toLowerCase().trim(), serviceReferences[ii]); } - else{ - String pid = (String)refs[i].getProperty(PRESERVED_SERVICE_PID); - pidToServiceReferenceMap.put(pid.toLowerCase().trim(), refs[i]); - pidToServiceReferenceMapCopy.put(pid.toLowerCase().trim(), refs[i]); - } } } } /* - * Parse default_menu.xml file. For each menu node, get the value of the attribut "pid" - * check if the pid exists in pidToServiceReferenceMap. If so, get the action and add to the parent menu - * If not, ignore this menu. At the end of each top menu or subgroup menu or before help menu, - * add "additions" so that new algorithms can be added on later + * Parse DEFAULT_MENU_FILE_NAME file. + * For each menu node, get the value of the attribute pid. + * Check if the pid exists in pidsToServiceReferences. + * If so, get the action and add to the parent menu. + * If not, ignore this menu. + * At the end of each top menu or subgroup menu or before help menu, add "additions" so that + * new algorithms can be added on later. * * What is the reasonable logic? - * If a plug-in has been specified in the default_menu.xml, always use that menu layout - * If a plug-in has not been specified in the default_menu.xml, use the menu_path - * specified in the properties file. + * If a plug-in has been specified in the DEFAULT_MENU_FILE_NAME, always use that menu layout + * If a plug-in specified in the DEFAULT_MENU_FILE_NAME, use the menu_path specified in the + * properties file. * If a plug-in specifies a label in the properties file, always use it. - * */ private void createMenuFromXML(String menuFilePath) throws InvalidSyntaxException{ - parseXmlFile(menuFilePath); - //get the root elememt - Element docEle = dom.getDocumentElement(); + parseXMLFile(menuFilePath); + // Get the root elememt. + Element documentElement = this.documentObjectModel.getDocumentElement(); - //get a nodelist of the top menu elements - NodeList topMenuList = docEle.getElementsByTagName(TAG_TOP_MENU); - if(topMenuList != null && topMenuList.getLength() > 0) { - for(int i = 0 ; i < topMenuList.getLength();i++) { - Element el = (Element)topMenuList.item(i); - processTopMenu(el); + // Get a nodelist of the top menu elements. + NodeList topMenuList = documentElement.getElementsByTagName(TAG_TOP_MENU); + + if ((topMenuList != null) && (topMenuList.getLength() > 0)) { + for (int ii = 0; ii < topMenuList.getLength(); ii++) { + Element element = (Element)topMenuList.item(ii); + processTopMenu(element); } } } - private void processTopMenu (Element topMenuNode){ - MenuManager topMenuBar = null; - + private void processTopMenu(Element topMenuNode) { /* - * The File and Help menus are created in ApplicationActionBarAdvisor.java - * This function now parses the XML file and appends the new menus/menu items to the correct group - * We first check to see if the menu already exists in our MenuBar. If it does, we modify the already - * existing menu. If not, then we create a new Menu. + * The File and Help menus are created in ApplicationActionBarAdvisor.java. + * This function now parses the XML file and appends the new menus/menu items to the + * correct group. + * We first check to see if the menu already exists in our MenuBar. + * If it does, we modify the already existing menu. If not, then we create a new Menu. * - * Modified by: Tim Kelley - * Date: May 8-9, 2007 * Additional code at: org.cishell.reference.gui.workspace.ApplicationActionBarAdvisor.java */ - String topMenuName = topMenuNode.getAttribute(ATTR_NAME); - if((topMenuBar = (MenuManager)menuBar.findUsingPath(topMenuName)) == null){ //Check to see if menu exists - topMenuBar= new MenuManager(topMenuName, topMenuName.toLowerCase()); //Create a new menu if it doesn't - menuBar.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, topMenuBar); + String topMenuName = topMenuNode.getAttribute(NAME_ATTRIBUTE); + MenuManager topMenuBar = (MenuManager)this.menuManager.findUsingPath(topMenuName); + + if (topMenuBar == null) { + topMenuBar = new MenuManager(topMenuName, topMenuName.toLowerCase()); + this.menuManager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, topMenuBar); } - //Second process submenu + // Second process submenu. processSubMenu(topMenuNode, topMenuBar); } /* - * Recursively process sub menu and group menu + * Recursively process sub menu and group menu. */ - private void processSubMenu (Element menuNode, MenuManager parentMenuBar){ - + private void processSubMenu(Element menuNode, MenuManager parentMenuBar){ NodeList subMenuList = menuNode.getElementsByTagName(TAG_MENU); - if(subMenuList != null && subMenuList.getLength() > 0) { - for(int i = 0 ; i < subMenuList.getLength();i++) { - Element el = (Element)subMenuList.item(i); + + if ((subMenuList != null) && (subMenuList.getLength() > 0)) { + for (int ii = 0; ii < subMenuList.getLength(); ii++) { + Element element = (Element)subMenuList.item(ii); - //only process direct children nodes and - //drop all grand or grand of grand children nodes - if (!el.getParentNode().equals(menuNode)) + /* + * Only process direct children nodes and drop all grand or grand of grand + * children nodes. + * TODO: Why? + */ + if (!element.getParentNode().equals(menuNode)) { continue; - - String menu_type = el.getAttribute(ATTR_TYPE); - String pid=el.getAttribute(ATTR_PID); - if ((menu_type == null || menu_type.length()==0)&& pid !=null){ - processAMenuNode(el, parentMenuBar); - } - else if (menu_type.equalsIgnoreCase(PRESERVED_GROUP)){ - String groupName = el.getAttribute(ATTR_NAME); + } + + String menuType = element.getAttribute(TYPE_ATTRIBUTE); + String algorithmPID = element.getAttribute(PID_ATTRIBUTE); + + if (((menuType == null) || (menuType.length() == 0)) && (algorithmPID != null)) { + processAMenuNode(element, parentMenuBar); + } else if (menuType.equalsIgnoreCase(PRESERVED_GROUP)) { + String groupName = element.getAttribute(NAME_ATTRIBUTE); MenuManager groupMenuBar = new MenuManager(groupName, groupName.toLowerCase()); parentMenuBar.add(groupMenuBar); - processSubMenu(el, groupMenuBar); + processSubMenu(element, groupMenuBar); } - else if (menu_type.equalsIgnoreCase(PRESERVED_BREAK)){ - //It seems that Framework automatically takes care of issues - //such as double separators, a separator at the top or bottom + else if (menuType.equalsIgnoreCase(PRESERVED_BREAK)){ + /* + * It seems that the framework automatically takes care of issues such as + * double separators and a separator at the top or bottom. + */ parentMenuBar.add(new Separator()); } - else if (menu_type.equalsIgnoreCase(PRESERVED)){ - String menuName = el.getAttribute(ATTR_NAME); + else if (menuType.equalsIgnoreCase(PRESERVED)){ + String menuName = element.getAttribute(NAME_ATTRIBUTE); if(menuName.equalsIgnoreCase(PRESERVED_EXIT) ){ //allow to add more menu before "File/Exit" if(parentMenuBar.getId().equalsIgnoreCase(IWorkbenchActionConstants.M_FILE)){ @@ -299,7 +351,7 @@ parentMenuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); parentMenuBar.add(new GroupMarker(END_GROUP)); } - IWorkbenchAction exitAction = ActionFactory.QUIT.create(window); + IWorkbenchAction exitAction = ActionFactory.QUIT.create(workbenchWindow); parentMenuBar.add(new Separator()); parentMenuBar.add(exitAction); } @@ -314,152 +366,166 @@ parentMenuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); parentMenuBar.add(new GroupMarker(END_GROUP)); } - - } - + } } /* - * process a menu (algorithm) + * TODO: Better name? + * Process a menu (algorithm). */ - private void processAMenuNode(Element menuNode, MenuManager parentMenuBar ){ - String menuName = menuNode.getAttribute(ATTR_NAME); - String pid = menuNode.getAttribute(ATTR_PID); - if (pid == null || pid.length()==0){ - //check if the name is one of the preserved one - //if so add the default action - } - else{ - //check if the pid has registered in pidToServiceReferenceMap - if (pidToServiceReferenceMapCopy.containsKey(pid.toLowerCase().trim())){ - ServiceReference ref = (ServiceReference) pidToServiceReferenceMapCopy. - get(pid.toLowerCase().trim()); - pidToServiceReferenceMap.remove(pid.toLowerCase().trim()); - AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext); - String menuLabel = (String)ref.getProperty(LABEL); - if(menuName!= null && menuName.trim().length()>0){ - //use the name specified in the xml to overwrite the label + private void processAMenuNode(Element menuNode, MenuManager parentMenuBar) { + String menuName = menuNode.getAttribute(NAME_ATTRIBUTE); + String pid = menuNode.getAttribute(PID_ATTRIBUTE); + + if ((pid == null) || (pid.length() == 0)) { + /* + * TODO: Check if the name is one of the preserved one, and add the default action if + * it is? + */ + } else { + // Check if the PID has registered in pidsToServiceReferences. + if (this.pidsToServiceReferencesCopy.containsKey(pid.toLowerCase().trim())){ + ServiceReference serviceReference = + (ServiceReference)this.pidsToServiceReferencesCopy.get( + pid.toLowerCase().trim()); + this.pidsToServiceReferences.remove(pid.toLowerCase().trim()); + AlgorithmAction action = + new AlgorithmAction(serviceReference, this.bundleContext, this.ciShellContext); + String menuLabel = (String)serviceReference.getProperty(LABEL); + + if ((menuName!= null) && (menuName.trim().length() > 0)) { + // Use the name specified in the XML to overwrite the label. action.setText(menuName); - action.setId(getItemID(ref)); + action.setId(getItemID(serviceReference)); parentMenuBar.add(action); - } - else{ - if (menuLabel!= null && menuLabel.trim().length()>0){ + handleActionAccelerator(action, parentMenuBar, serviceReference); + } else { + if ((menuLabel != null) && (menuLabel.trim().length() > 0)) { action.setText(menuLabel); - action.setId(getItemID(ref)); - parentMenuBar.add(action); + action.setId(getItemID(serviceReference)); + parentMenuBar.add(action); + handleActionAccelerator(action, parentMenuBar, serviceReference); + } else { + /* + * TODO: This is a problem: No label is specified in the plug-in's + * properties file and no name is specified in the XML file. + */ } - else { - //this is a problem -- no label is specified in the plug-in's properties file - //and no name is specified in the xml file. - } } + } else { + String algorithmNotFoundMessage = + "Oops! Network Workbench tried to place an algorithm with the id '" + + pid + + "' on the menu, but the algorithm could not be found."; + String contactInformationMessage = + "If you see this error, please contact nwb...@go..., or " + + "post a ticket on our bug tracker at: " + + "http://cns-trac.slis.indiana.edu/trac/nwb ."; + this.logger.log(LogService.LOG_DEBUG, algorithmNotFoundMessage); + this.logger.log(LogService.LOG_DEBUG, contactInformationMessage); } - else{ - //otherwise log the error - getLog().log(LogService.LOG_DEBUG, - "Oops! Network Workbench tried to place an algorithm with the id '" + pid + "' on the menu, but the algorithm could not be found."); - getLog().log(LogService.LOG_DEBUG, "If you see this error, please contact nwb...@go..., or post a ticket on our bug tracker at " + - "http://cns-trac.slis.indiana.edu/trac/nwb ."); - } } } - private void parseXmlFile(String menuFilePath){ - //get the factory - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setCoalescing(true); - try { - //Using factory get an instance of document builder - DocumentBuilder db = dbf.newDocumentBuilder(); - - //parse using builder to get DOM representation of the XML file - dom = db.parse(menuFilePath); - // printElementAttributes(dom); + private void parseXMLFile(String menuFilePath){ + DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); + documentBuilderFactory.setCoalescing(true); - }catch(ParserConfigurationException pce) { - pce.printStackTrace(); - }catch(SAXException se) { - se.printStackTrace(); - }catch(IOException ioe) { - ioe.printStackTrace(); + try { + DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + + this.documentObjectModel = documentBuilder.parse(menuFilePath); + + } catch(ParserConfigurationException parserConfigurationException) { + parserConfigurationException.printStackTrace(); + } catch(SAXException saxException) { + saxException.printStackTrace(); + } catch(IOException ioException) { + ioException.printStackTrace(); } } /* * Handle some service bundles that have specified the menu_path and label - * but not specified in the default_menu.xml + * but not specified in the DEFAULT_MENU_FILE_NAME */ - private void processLeftServiceBundles(){ - if (!pidToServiceReferenceMap.isEmpty()){ - Object[] keys = pidToServiceReferenceMap.keySet().toArray(); - for (int i=0; i<keys.length; i++){ - ServiceReference ref= (ServiceReference) - pidToServiceReferenceMap.get((String)keys[i]); - makeMenuItem(ref); + private void processLeftServiceBundles() { + if (!this.pidsToServiceReferences.isEmpty()){ + Object[] keys = this.pidsToServiceReferences.keySet().toArray(); + + for (int ii = 0; ii < keys.length; ii++) { + ServiceReference serviceReference = + (ServiceReference)this.pidsToServiceReferences.get((String)keys[ii]); + makeMenuItem(serviceReference); } } } - private void initializeMenu() throws InvalidSyntaxException{ - ServiceReference[] refs = bContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), null); + ServiceReference[] serviceReferences = this.bundleContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), null); - if (refs != null) { - for (int i=0; i < refs.length; i++) { - makeMenuItem(refs[i]); + if (serviceReferences != null) { + for (int ii = 0; ii < serviceReferences.length; ii++) { + makeMenuItem(serviceReferences[ii]); } } + } - } - - private class ContextListener implements ServiceListener { public void serviceChanged(ServiceEvent event) { switch (event.getType()) { case ServiceEvent.REGISTERED: makeMenuItem(event.getServiceReference()); + break; case ServiceEvent.UNREGISTERING: removeMenuItem(event.getServiceReference()); + break; case ServiceEvent.MODIFIED: updateMenuItem(event.getServiceReference()); + break; } } } - private void makeMenuItem(ServiceReference ref) { - String path = (String)ref.getProperty(MENU_PATH); - String[] items = (path == null) ? null : path.split("/"); + private void makeMenuItem(ServiceReference serviceReference) { + String path = (String)serviceReference.getProperty(MENU_PATH); + String[] items = null; + + if (path != null) { + items = path.split("/"); + } + IMenuManager menu = null; - if (items != null && items.length > 1) { - AlgorithmAction action = new AlgorithmAction(ref, bContext, ciContext); - action.setId(getItemID(ref)); + + if ((items != null) && (items.length > 1)) { + AlgorithmAction action = + new AlgorithmAction(serviceReference, this.bundleContext, this.ciShellContext); + action.setId(getItemID(serviceReference)); - IMenuManager targetMenu = menuBar; - String group = items[items.length-1]; + IMenuManager targetMenu = this.menuManager; + String group = items[items.length - 1]; - for (int i=0; i < items.length-1; i++) { - - menu = targetMenu.findMenuUsingPath(items[i]); + for (int ii = 0; ii < items.length - 1; ii++) { + menu = targetMenu.findMenuUsingPath(items[ii]); - if (menu == null && items[i] != null) { - menu = targetMenu.findMenuUsingPath(items[i].toLowerCase()); + if ((menu == null) && (items[ii] != null)) { + menu = targetMenu.findMenuUsingPath(items[ii].toLowerCase()); } if (menu == null) { - menu = createMenu(items[i],items[i]); + menu = createMenu(items[ii], items[ii]); targetMenu.appendToGroup(ADDITIONS_GROUP, menu); } targetMenu = menu; } - group = items[items.length-1]; + group = items[items.length - 1]; IContributionItem groupItem = targetMenu.find(group); if (groupItem == null) { @@ -468,98 +534,124 @@ } targetMenu.appendToGroup(group, action); + handleActionAccelerator(action, targetMenu, serviceReference); targetMenu.appendToGroup(group, new Separator()); - algorithmToItemMap.put(getItemID(ref), action); - itemToParentMap.put(action, targetMenu); + algorithmsToItems.put(getItemID(serviceReference), action); + itemsToParents.put(action, targetMenu); - Display.getDefault().asyncExec(updateAction); + Display.getDefault().asyncExec(this.updateAction); } else { - getLog().log(LogService.LOG_DEBUG, - "Bad menu path for Algorithm: " + ref.getProperty(LABEL)); + this.logger.log( + LogService.LOG_DEBUG, + "Bad menu path for Algorithm: " + serviceReference.getProperty(LABEL)); } } - private Runnable updateAction = new Runnable() { - public void run() { - menuBar.updateAll(true); - } - }; - - private String getItemID(ServiceReference ref) { - return ref.getProperty("PID:" + Constants.SERVICE_PID) + "-SID:" + - ref.getProperty(Constants.SERVICE_ID); + private String getItemID(ServiceReference serviceReference) { + return + serviceReference.getProperty("PID:" + Constants.SERVICE_PID) + + "-SID:" + + serviceReference.getProperty(Constants.SERVICE_ID); } - + private MenuManager createMenu(String name, String id){ MenuManager menu = new MenuManager(name, id); menu.add(new GroupMarker(START_GROUP)); menu.add(new GroupMarker(ADDITIONS_GROUP)); menu.add(new GroupMarker(END_GROUP)); + return menu; } - - private void updateMenuItem(ServiceReference ref) { - Action item = (Action) algorithmToItemMap.get(getItemID(ref)); + + private void updateMenuItem(ServiceReference serviceReference) { + Action item = (Action)this.algorithmsToItems.get(getItemID(serviceReference)); - if (item != null) - item.setText(""+ref.getProperty(LABEL)); + if (item != null) { + this.logger.log( + LogService.LOG_DEBUG, "updateMenuItem for " + getItemID(serviceReference)); + item.setText("" + serviceReference.getProperty(LABEL)); + } } - private void removeMenuItem(ServiceReference ref) { - String path = (String)ref.getProperty(MENU_PATH); - final Action item = (Action) algorithmToItemMap.get(getItemID(ref)); + private void removeMenuItem(ServiceReference serviceReference) { + String path = (String)serviceReference.getProperty(MENU_PATH); + final Action item = (Action)this.algorithmsToItems.get(getItemID(serviceReference)); - if (path != null && item != null) { + if ((path != null) && (item != null)) { int index = path.lastIndexOf('/'); + if (index != -1) { path = path.substring(0, index); - - final IMenuManager targetMenu = menuBar.findMenuUsingPath(path); + final IMenuManager targetMenu = this.menuManager.findMenuUsingPath(path); if (targetMenu != null) { - - if (!shell.isDisposed()) { - shell.getDisplay().syncExec(new Runnable() { - public void run() { - targetMenu.remove(item.getId()); - }}); + if (!this.shell.isDisposed()) { + this.shell.getDisplay().syncExec(new Runnable() { + public void run() { + targetMenu.remove(item.getId()); + } + }); } - - - algorithmToItemMap.remove(getItemID(ref)); - itemToParentMap.remove(item); + + this.algorithmsToItems.remove(getItemID(serviceReference)); + this.itemsToParents.remove(item); } } } } - - private Runnable stopAction = new Runnable() { - public void run() { - String[] algs = (String[]) - algorithmToItemMap.keySet().toArray(new String[]{}); - - for (int i=0; i < algs.length; i++) { - Action item = (Action)algorithmToItemMap.get(algs[i]); - IMenuManager targetMenu = (IMenuManager)itemToParentMap.get(item); - - targetMenu.remove(item.getId()); - algorithmToItemMap.remove(algs[i]); - itemToParentMap.remove(item); - } - } - }; - + public void stop() { - bContext.removeServiceListener(listener); + this.bundleContext.removeServiceListener(this.contextListener); - if (!shell.isDisposed()) { - shell.getDisplay().syncExec(stopAction); + if (!this.shell.isDisposed()) { + this.shell.getDisplay().syncExec(this.stopAction); } } - - private LogService getLog() { - return (LogService) ciContext.getService(LogService.class.getName()); - } + + //private void clearShortcuts() { + /*IWorkbench workbench = this.window.getWorkbench(); + IBindingService bindingService = + (IBindingService)workbench.getService(IBindingService.class); + Binding[] bindings = bindingService.getBindings(); + IHandlerService handlerService = + (IHandlerService)workbench.getService(IHandlerService.class);*/ + //getLog().log(LogService.LOG_WARNING, "handlerService: " + handlerService); + //for (int ii = 0; ii < bindings.length; ii++) { + // getLog().log(LogService.LOG_INFO, "Binding[" + ii + "]: " + bindings[ii]); + /*String bindingInfo = + "\tcontextID: " + bindings[ii].getContextId() + "\n" + + "\tparameterized command: " + bindings[ii].getParameterizedCommand() + "\n" + + "\ttrigger sequence: " + bindings[ii].getTriggerSequence().format(); + getLog().log(LogService.LOG_INFO, "Binding:\n" + bindingInfo);*/ + + /*KeyBinding( + bindings[ii].getTriggerSequence(), + null, + bindings[ii].getSchemeId(), + bindings[ii].getContextId(), + null, + null, + null, + Binding.SYSTEM);*/ + //} + //} + + private void handleActionAccelerator( + Action action, IMenuManager parentMenuBar, ServiceReference serviceReference) { + action.setAccelerator(determineActionAcceleratorKeyCode(serviceReference, action)); + } + + private static int determineActionAcceleratorKeyCode( + ServiceReference serviceReference, Action action) { + String shortcutString = (String)serviceReference.getProperty(SHORTCUT); + + if (shortcutString != null) { + return action.convertAccelerator(shortcutString); + } else { + return 0; + } + } + /* * printElementAttributes takes in a xml document, gets the nodes, then prints the attributes. * Copied from Java Tutorial on XML Parsing by Tim Kelley for debugging purposes. Modified: trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/ApplicationActionBarAdvisor.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/ApplicationActionBarAdvisor.java 2009-12-04 23:11:02 UTC (rev 988) +++ trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/ApplicationActionBarAdvisor.java 2009-12-04 23:14:01 UTC (rev 989) @@ -1,7 +1,11 @@ package org.cishell.reference.gui.workspace; +import java.io.BufferedWriter; +import java.io.FileWriter; + import org.eclipse.jface.action.GroupMarker; +import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; @@ -79,8 +83,18 @@ menu.add(new GroupMarker("start")); menu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); menu.add(new GroupMarker("end")); - //System.out.println(IWorkbenchActionConstants.MB_ADDITIONS); + return menu; } - + +// protected void register(IAction action) { +// try { +// FileWriter fstream = new FileWriter("C:/Documents and Settings/pataphil/Desktop/out.txt", true); +// BufferedWriter out = new BufferedWriter(fstream); +// out.write("action: " + action + "\r\n"); +// out.close(); +// } catch (Exception e) { +// System.err.println("Error: " + e.getMessage()); +// } +// } } Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmProperty.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmProperty.java 2009-12-04 23:11:02 UTC (rev 988) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmProperty.java 2009-12-04 23:14:01 UTC (rev 989) @@ -48,6 +48,7 @@ public static final String ADDITIONS_GROUP = "additions"; public static final String START_GROUP = "start"; public static final String END_GROUP = "end"; + public static final String SHORTCUT = "shortcut"; public static final String CONVERSION = "conversion"; public static final String LOSSY = "lossy"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-12-04 23:11:09
|
Revision: 988 http://cishell.svn.sourceforge.net/cishell/?rev=988&view=rev Author: pataphil Date: 2009-12-04 23:11:02 +0000 (Fri, 04 Dec 2009) Log Message: ----------- * Fixed a minor classpath issue. * Reviewed by Micah. Modified Paths: -------------- trunk/core/org.cishell.reference/.classpath Modified: trunk/core/org.cishell.reference/.classpath =================================================================== --- trunk/core/org.cishell.reference/.classpath 2009-11-30 23:33:35 UTC (rev 987) +++ trunk/core/org.cishell.reference/.classpath 2009-12-04 23:11:02 UTC (rev 988) @@ -1,7 +1,7 @@ <?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/j2sdk1.4.2_19"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> </classpath> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-11-30 23:33:44
|
Revision: 987 http://cishell.svn.sourceforge.net/cishell/?rev=987&view=rev Author: pataphil Date: 2009-11-30 23:33:35 +0000 (Mon, 30 Nov 2009) Log Message: ----------- * The load file format selection window now selects the first option by default. * The Select buttons in the load and save file format selection windows is now focused by default, so the user can just hit enter to use the default option. * Cleaned up SavedataChooser a bit. * Users can now double-click options in the save file format selection window to choose it (similarly to the load file format selection window in a previous commit.) Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2009-11-30 22:24:29 UTC (rev 986) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2009-11-30 23:33:35 UTC (rev 987) @@ -15,8 +15,8 @@ import org.cishell.framework.data.Data; import org.cishell.reference.gui.common.AbstractDialog; import org.eclipse.swt.SWT; +import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; @@ -100,19 +100,14 @@ this.persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); // initPersisterArray(); - initPersisterList(); - this.persisterList.addMouseListener(new MouseListener() { - public void mouseUp(MouseEvent mouseEvent) { - } - - public void mouseDown(MouseEvent mouseEvent) { - } - + initializePersisterList(); + this.persisterList.addMouseListener(new MouseAdapter() { public void mouseDoubleClick(MouseEvent mouseEvent) { - int index = FileFormatSelector.this.persisterList.getSelectionIndex(); + List list = (List)mouseEvent.getSource(); + int selection = list.getSelectionIndex(); - if (index != -1) { - selectionMade(index); + if (selection != -1) { + selectionMade(selection); } } }); @@ -127,6 +122,8 @@ } } }); + + persisterList.setSelection(0); /* Group detailsGroup = new Group(content, SWT.NONE); // Shall this label be moved out of the code? @@ -144,7 +141,7 @@ return content; } - private void initPersisterList() { + private void initializePersisterList() { for (int ii = 0; ii < this.persisterArray.length; ++ii) { String name = (String)this.persisterArray[ii].getProperty("label"); @@ -230,6 +227,7 @@ } } }); + select.setFocus(); Button cancel = new Button(parent, SWT.NONE); cancel.setText("Cancel"); Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2009-11-30 22:24:29 UTC (rev 986) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2009-11-30 23:33:35 UTC (rev 987) @@ -42,7 +42,7 @@ * Initializes services to output messages * * @param parent - * @param context + * @param ciShellContext */ public FileSaver(Shell parent, CIShellContext context){ this.parent = parent; Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2009-11-30 22:24:29 UTC (rev 986) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2009-11-30 23:33:35 UTC (rev 987) @@ -37,7 +37,7 @@ * * @param data The data array to persist * @param parameters Parameters for the algorithm - * @param context Provides services to CIShell services + * @param ciShellContext Provides services to CIShell services */ public Save(Data[] data, Dictionary parameters, CIShellContext context) { this.data = data; Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2009-11-30 22:24:29 UTC (rev 986) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2009-11-30 23:33:35 UTC (rev 987) @@ -21,6 +21,8 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; @@ -37,36 +39,39 @@ /** * SaveDataChooser is a simple user interface to allow for selection - * among several Persisters that support the selected model, in the event + * among several persisters that support the selected model, in the event * that more than one is found. - * - * @author Team IVC */ public class SaveDataChooser extends AbstractDialog implements AlgorithmProperty { + public static final Image QUESTION_ICON = + Display.getCurrent().getSystemImage(SWT.ICON_QUESTION); + protected Data data; - protected Converter[] converterArray; - private List converterList; + protected Converter[] converters; + private List converterListComponent; private StyledText detailPane; - //private Shell parent; - CIShellContext context; - public static final Image QUESTION = Display.getCurrent().getSystemImage(SWT.ICON_QUESTION); + CIShellContext ciShellContext; /** * Creates a new SaveChooser object. * * @param data The data object to save * @param parent The parent shell - * @param converterArray The array of converters to persist the data + * @param converters The array of converters to persist the data * @param title Title of the Window * @param brandPluginID The plugin that supplies the branding - * @param context The CIShellContext to retrieve available services + * @param ciShellContext The CIShellContext to retrieve available services */ - public SaveDataChooser(Data data, Shell parent, Converter[] converterArray, - String title, CIShellContext context) { - super(parent, title, QUESTION); + public SaveDataChooser( + Data data, + Shell parent, + Converter[] converters, + String title, + CIShellContext ciShellContext) { + super(parent, title, QUESTION_ICON); this.data = data; - this.converterArray = alphabetizeConverters(filterConverters(converterArray)); - this.context = context; + this.converters = alphabetizeConverters(filterConverters(converters)); + this.ciShellContext = ciShellContext; } /** @@ -74,12 +79,11 @@ * @param parent The parent window * @return The new window containing the chooser */ - private Composite initGUI(Composite parent) { + private Composite initializeGUI(Composite parent) { Composite content = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; content.setLayout(layout); - //parent.setLayout(layout); Group converterGroup = new Group(content, SWT.NONE); converterGroup.setText("Pick the Output Data Type"); @@ -88,18 +92,29 @@ persisterData.widthHint = 200; converterGroup.setLayoutData(persisterData); - converterList = new List(converterGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE); - initConverterList(); - converterList.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - List list = (List) e.getSource(); - int selection = list.getSelectionIndex(); + converterListComponent = + new List(converterGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE); + initializeConverterListComponent(); + converterListComponent.addMouseListener(new MouseAdapter() { + public void mouseDoubleClick(MouseEvent mouseEvent) { + List list = (List)mouseEvent.getSource(); + int selection = list.getSelectionIndex(); + + if (selection != -1) { + selectionMade(selection); + } + } + }); + converterListComponent.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent selectionEvent) { + List list = (List)selectionEvent.getSource(); + int selection = list.getSelectionIndex(); - if (selection != -1) { - updateDetailPane(converterArray[selection]); - } - } - }); + if (selection != -1) { + updateDetailPane(converters[selection]); + } + } + }); Group detailsGroup = new Group(content, SWT.NONE); detailsGroup.setText("Details"); @@ -107,45 +122,47 @@ GridData detailsData = new GridData(GridData.FILL_BOTH); detailsData.widthHint = 200; detailsGroup.setLayoutData(detailsData); - - detailPane = initDetailPane(detailsGroup); - //select the first item by default - converterList.setSelection(0); - updateDetailPane(converterArray[0]); - + detailPane = initializeDetailPane(detailsGroup); + + // Select the first item by default. + converterListComponent.setSelection(0); + updateDetailPane(converters[0]); + return content; } /** * Initialize the Listbox of Persisters using the stored Persister array */ - private void initConverterList() { - for (int i = 0; i < converterArray.length; ++i) { - if (converterArray[i] != null) { - Dictionary dict = converterArray[i].getProperties(); + private void initializeConverterListComponent() { + for (int ii = 0; ii < converters.length; ii++) { + if (converters[ii] != null) { + Dictionary converterProperties = converters[ii].getProperties(); - // get the name of the persister from the property map + // Get the name of the persister from the property map. String outData = null; - ServiceReference[] refs = converterArray[i].getConverterChain(); - if (refs != null && refs.length > 0) { - outData = (String) refs[refs.length-1].getProperty( - AlgorithmProperty.LABEL); + ServiceReference[] serviceReferences = converters[ii].getConverterChain(); + + if ((serviceReferences != null) && (serviceReferences.length > 0)) { + outData = (String)serviceReferences[serviceReferences.length - 1].getProperty( + AlgorithmProperty.LABEL); } - + if (outData == null) { - outData = (String) dict.get(AlgorithmProperty.LABEL); + outData = (String)converterProperties.get(AlgorithmProperty.LABEL); } - // if someone was sloppy enough to not provide a name, then use - // the - // name of the class instead. + /* + * If someone was sloppy enough to not provide a name, then use the name of the + * class instead. + */ if ((outData == null) || (outData.length() == 0)) { - outData = converterArray[i].getClass().getName(); + outData = converters[ii].getClass().getName(); } - converterList.add(outData); + converterListComponent.add(outData); } } } @@ -158,7 +175,7 @@ * The detail pane to init * @return A style of the text */ - private StyledText initDetailPane(Group detailsGroup) { + private StyledText initializeDetailPane(Group detailsGroup) { StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); detailPane.setEditable(false); detailPane.getCaret().setVisible(false); @@ -172,14 +189,14 @@ * @param converter A converter that contains the properties for the detail pane */ private void updateDetailPane(Converter converter) { - Dictionary dict = converter.getProperties(); - Enumeration keysEnum = dict.keys(); + Dictionary converterProperties = converter.getProperties(); + Enumeration converterPropertiesKeys = converterProperties.keys(); detailPane.setText(""); - while (keysEnum.hasMoreElements()) { - Object key = keysEnum.nextElement(); - Object val = dict.get(key); + while (converterPropertiesKeys.hasMoreElements()) { + Object key = converterPropertiesKeys.nextElement(); + Object value = converterProperties.get(key); StyleRange styleRange = new StyleRange(); styleRange.start = detailPane.getText().length(); @@ -188,7 +205,7 @@ styleRange.fontStyle = SWT.BOLD; detailPane.setStyleRange(styleRange); - detailPane.append(val + "\n"); + detailPane.append(value + "\n"); } } @@ -209,26 +226,23 @@ private Converter[] filterConverters(Converter[] allConverters) { Map lastInDataToConverter = new HashMap(); - for (int i = 0; i < allConverters.length; i++) { - Converter converter = allConverters[i]; - - - - //for .xml files, to uniquely identify it - //we need to know what kind of xml it was - //so we look at the in_data type of the - //last converter - String lastInData = getLastConverterInData(converter); - - //if we already have a converter with this out data type... - if (lastInDataToConverter.containsKey(lastInData)) { - Converter alreadyStoredConverter = (Converter) lastInDataToConverter.get(lastInData); - - Converter chosenConverter = returnPreferredConverter(converter,alreadyStoredConverter); - - lastInDataToConverter.put(lastInData, chosenConverter); + for (int ii = 0; ii < allConverters.length; ii++) { + Converter converter = allConverters[ii]; + + /* + * To uniquely identify an XML file, we need to know what kind of XML it was so we look + * at the input data type of the last converter. + */ + String lastInputData = getLastConverterInData(converter); + + if (lastInDataToConverter.containsKey(lastInputData)) { + Converter alreadyStoredConverter = + (Converter)lastInDataToConverter.get(lastInputData); + Converter chosenConverter = + returnPreferredConverter(converter, alreadyStoredConverter); + lastInDataToConverter.put(lastInputData, chosenConverter); } else { - lastInDataToConverter.put(lastInData, converter); + lastInDataToConverter.put(lastInputData, converter); } } @@ -237,11 +251,11 @@ private String getLastConverterInData(Converter converter) { ServiceReference[] convChain = converter.getConverterChain(); + if (convChain.length >= 1) { - ServiceReference lastConv = convChain[convChain.length - 1]; - - String lastInData = (String) lastConv.getProperty("in_data"); - + ServiceReference lastConverter = convChain[convChain.length - 1]; + String lastInData = (String) lastConverter.getProperty("in_data"); + return lastInData; } else { return ""; @@ -251,87 +265,88 @@ /** * Returns whichever converter is better to show to the user in the chooser, * based on lossiness, and length of converter chain - * @param c1 A converter with the same out_data type as the other - * @param c2 A converter with the same out_data type as the other + * @param converter1 A converter with the same out_data type as the other + * @param converter2 A converter with the same out_data type as the other * @return The preferred converter of the two */ - private Converter returnPreferredConverter(Converter c1, Converter c2) { - Dictionary c1Dict = c1.getProperties(); - String c1Lossiness = (String) c1Dict.get(CONVERSION); - int c1Quality = determineQuality(c1Lossiness); + private Converter returnPreferredConverter(Converter converter1, Converter converter2) { + Dictionary converter1Properties = converter1.getProperties(); + String converter1Lossiness = (String)converter1Properties.get(CONVERSION); + int converter1Quality = determineQuality(converter1Lossiness); + + Dictionary converter2Properties = converter2.getProperties(); + String converter2Lossiness = (String)converter2Properties.get(CONVERSION); + int converter2Quality = determineQuality(converter2Lossiness); - - - Dictionary c2Dict = c2.getProperties(); - String c2Lossiness = (String) c2Dict.get(CONVERSION); - int c2Quality = determineQuality(c2Lossiness); - - if (c1Quality > c2Quality) { - return c1; - } else if (c2Quality > c1Quality) { - return c2; + if (converter1Quality > converter2Quality) { + return converter1; + } else if (converter2Quality > converter1Quality) { + return converter2; } else { - //they are tied. Look at converter chain length + // They are tied. Look at converter chain length. - int c1Length = c1.getConverterChain().length; - int c2Length = c2.getConverterChain().length; - //return the shortest - if (c1Length > c2Length) { - return c2; - } else if (c2Length > c1Length) { - return c1; + int converter1Length = converter1.getConverterChain().length; + int converter2Length = converter2.getConverterChain().length; + + if (converter1Length > converter2Length) { + return converter2; + } else if (converter2Length > converter1Length) { + return converter1; } else { - //both have the same lossiness and same length - //arbitrary pick the first - return c1; + /* + * Both have the same lossiness and same length. + * Arbitrary pick the first. + */ + return converter1; } } } - + private int determineQuality(String lossiness) { if (lossiness == LOSSY) { return 0; } else if (lossiness == null) { return 1; - } else { //lossiness == LOSSLESS + // Lossiness == LOSSLESS. + } else { return 2; } } - - private Converter[] alphabetizeConverters(Converter[] cs) { - Arrays.sort(cs, new CompareAlphabetically()); - return cs; + + private Converter[] alphabetizeConverters(Converter[] converters) { + Arrays.sort(converters, new CompareAlphabetically()); + + return converters; } /** * When a Persister is chosen to Persist this model, this method handles the job * of opening the FileSaver and saving the model. - * @param selectedIndex The chosen converter + * @param selectedIndex The chosen converter. */ protected void selectionMade(int selectedIndex) { try { getShell().setVisible(false); - final Converter converter = converterArray[selectedIndex]; - final FileSaver saver = new FileSaver(getShell(), context); + final Converter converter = converters[selectedIndex]; + final FileSaver saver = new FileSaver(getShell(), ciShellContext); close(saver.save(converter, data)); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (Exception exception) { + throw new RuntimeException(exception); } } /** - * Create the buttons for either cancelling or continuing with - * the save + * Create the buttons for either cancelling or continuing with the save. * - * @param parent The GUI to place the buttons + * @param parent The GUI to place the buttons. */ public void createDialogButtons(Composite parent) { Button select = new Button(parent, SWT.PUSH); select.setText("Select"); select.addSelectionListener( new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - int index = converterList.getSelectionIndex(); + public void widgetSelected(SelectionEvent selectionEvent) { + int index = converterListComponent.getSelectionIndex(); if (index != -1) { selectionMade(index); @@ -339,12 +354,13 @@ } } ); + select.setFocus(); Button cancel = new Button(parent, SWT.NONE); cancel.setText("Cancel"); cancel.addSelectionListener( new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent selectionEvent) { close(false); } } @@ -352,55 +368,53 @@ } /** - * Checks for the number of file savers. If there is one - * converter then it will save directly, otherwise initialize the chooser. + * Checks for the number of file savers. If there is one converter then it will save directly, + * otherwise initialize the chooser. * * @param parent The parent GUI for new dialog windows. */ public Composite createContent(Composite parent) { - if (converterArray.length == 1) { - final FileSaver saver = new FileSaver((Shell) parent, context); - close(saver.save(converterArray[0], data)); + if (converters.length == 1) { + final FileSaver saver = new FileSaver((Shell) parent, ciShellContext); + close(saver.save(converters[0], data)); + return parent; } else { - return initGUI(parent); + return initializeGUI(parent); } } private class CompareAlphabetically implements Comparator { - public int compare(Object o1, Object o2) { - if (o1 instanceof Converter && o2 instanceof Converter) { - Converter c1 = (Converter) o1; - String c1Label = getLabel(c1); + public int compare(Object object1, Object object2) { + if ((object1 instanceof Converter) && (object2 instanceof Converter)) { + Converter converter1 = (Converter)object1; + String converter1Label = getLabel(converter1); - Converter c2 = (Converter) o2; - String c2Label = getLabel(c2); + Converter converter2 = (Converter)object2; + String converter2Label = getLabel(converter2); - if (c1Label != null && c2Label != null) { - return c1Label.compareTo(c2Label); - } else if (c1Label == null) { - //c1 > c2 + if ((converter1Label != null) && (converter2Label != null)) { + return converter1Label.compareTo(converter2Label); + } else if (converter1Label == null) { return 1; - } else if (c2Label == null) { - //c1 < c2 + } else if (converter2Label == null) { return -1; } else { - //c1 == c2 return 0; } } else { - throw new IllegalArgumentException("Can only " + - "compare Converters"); + throw new IllegalArgumentException("Can only compare Converters"); } } - - private String getLabel(Converter c) { - String label = ""; - ServiceReference[] refs = c.getConverterChain(); - if (refs != null && refs.length > 0) { - label = (String) refs[refs.length-1].getProperty( - AlgorithmProperty.LABEL); + + private String getLabel(Converter converter) { + String label = ""; + ServiceReference[] serviceReferences = converter.getConverterChain(); + + if ((serviceReferences != null) && (serviceReferences.length > 0)) { + label = (String)serviceReferences[serviceReferences.length - 1].getProperty( + AlgorithmProperty.LABEL); } return label; Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2009-11-30 22:24:29 UTC (rev 986) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2009-11-30 23:33:35 UTC (rev 987) @@ -20,8 +20,8 @@ private CIShellContext ciShellContext; /** - * Create a local CIShell context - * @param componentContext The current CIShell context + * Create a local CIShell ciShellContext + * @param componentContext The current CIShell ciShellContext */ protected void activate(ComponentContext componentContext) { ciShellContext = Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java 2009-11-30 22:24:29 UTC (rev 986) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/ViewDataChooser.java 2009-11-30 23:33:35 UTC (rev 987) @@ -21,7 +21,7 @@ protected void selectionMade(int selectedIndex) { getShell().setVisible(false); - this.selectedConverter = converterArray[selectedIndex]; + this.selectedConverter = converters[selectedIndex]; close(true); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-11-30 22:25:22
|
Revision: 986 http://cishell.svn.sourceforge.net/cishell/?rev=986&view=rev Author: pataphil Date: 2009-11-30 22:24:29 +0000 (Mon, 30 Nov 2009) Log Message: ----------- * Cleaned up FileFormatSelector code a little bit. * Implemented double-click selection behavior for file format selector. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2009-11-30 19:30:56 UTC (rev 985) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2009-11-30 22:24:29 UTC (rev 986) @@ -15,8 +15,8 @@ import org.cishell.framework.data.Data; import org.cishell.reference.gui.common.AbstractDialog; import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.FillLayout; @@ -31,14 +31,9 @@ import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; -/** - * - * @author Team IVC (Weixia Huang, James Ellis) - */ public class FileFormatSelector extends AbstractDialog { private File selectedFile; private LogService logger; - private ServiceReference[] persisterArray; private List persisterList; // private StyledText detailPane; @@ -57,31 +52,38 @@ // {"Format name", "Supported file extension", "Format description"}; /* - * Other possible keys display values could be "Restorable model name", "Restorable model description" - * */ + * Other possible keys display values could be "Restorable model name", + * "Restorable model description" + */ - public FileFormatSelector(String title, File theFile, - Shell parent, CIShellContext ciContext, BundleContext bContext, - ServiceReference[] persisterArray, ArrayList returnList){ + public FileFormatSelector( + String title, + File selectedFile, + Shell parent, + CIShellContext ciShellContext, + BundleContext bundleContext, + ServiceReference[] persisterArray, + ArrayList returnList) { super(parent, title, AbstractDialog.QUESTION); - this.ciShellContext = ciContext; - this.bundleContext = bContext; + this.ciShellContext = ciShellContext; + this.bundleContext = bundleContext; this.persisterArray = persisterArray; this.returnList = returnList; + this.selectedFile = selectedFile; + this.logger = (LogService)ciShellContext.getService(LogService.class.getName()); - this.selectedFile = theFile; - - this.logger = (LogService) ciContext.getService(LogService.class.getName()); - //shall this part be moved out of the code? - setDescription("The file you have selected can be loaded" - + " using one or more of the following formats.\n" - + "Please select the format you would like to try."); - setDetails("This dialog allows the user to choose among all available " + - "formats for loading the selected data model. Choose any of the formats " + - "to continue loading the dataset."); + // Shall this part be moved out of the code? + setDescription( + "The file you have selected can be loaded" + + " using one or more of the following formats.\n" + + "Please select the format you would like to try."); + setDetails( + "This dialog allows the user to choose among all available " + + "formats for loading the selected data model. Choose any of the formats " + + "to continue loading the dataset."); } - private Composite initGUI(Composite parent) { + private Composite initializeGUI(Composite parent) { Composite content = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); @@ -89,106 +91,130 @@ content.setLayout(layout); Group persisterGroup = new Group(content, SWT.NONE); - //shall this label be moved out of the code? + // Shall this label be moved out of the code? persisterGroup.setText("Load as..."); persisterGroup.setLayout(new FillLayout()); GridData persisterListGridData = new GridData(GridData.FILL_BOTH); persisterListGridData.widthHint = 200; persisterGroup.setLayoutData(persisterListGridData); - persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); - // initPersisterArray(); + this.persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); + // initPersisterArray(); initPersisterList(); - persisterList.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - List list = (List)e.getSource(); + this.persisterList.addMouseListener(new MouseListener() { + public void mouseUp(MouseEvent mouseEvent) { + } + + public void mouseDown(MouseEvent mouseEvent) { + } + + public void mouseDoubleClick(MouseEvent mouseEvent) { + int index = FileFormatSelector.this.persisterList.getSelectionIndex(); + + if (index != -1) { + selectionMade(index); + } + } + }); + + this.persisterList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent selectionEvent) { + List list = (List)selectionEvent.getSource(); int selection = list.getSelectionIndex(); - if(selection != -1){ -// updateDetailPane(persisterArray[selection]); + + if (selection != -1) { + // updateDetailPane(persisterArray[selection]); } } }); -// Group detailsGroup = new Group(content, SWT.NONE); -// // shall this label be moved out of the code? -// detailsGroup.setText("Details"); -// detailsGroup.setLayout(new FillLayout()); -// GridData detailsGridData = new GridData(GridData.FILL_BOTH); -// detailsGridData.widthHint = 200; -// detailsGroup.setLayoutData(detailsGridData); -// -// detailPane = initDetailPane(detailsGroup); -// -// persisterList.setSelection(0); -// updateDetailPane(persisterArray[0]); + /* Group detailsGroup = new Group(content, SWT.NONE); + // Shall this label be moved out of the code? + detailsGroup.setText("Details"); + detailsGroup.setLayout(new FillLayout()); + GridData detailsGridData = new GridData(GridData.FILL_BOTH); + detailsGridData.widthHint = 200; + detailsGroup.setLayoutData(detailsGridData); - return content; + detailPane = initDetailPane(detailsGroup); + + persisterList.setSelection(0); + updateDetailPane(persisterArray[0]); */ + + return content; } - private void initPersisterList(){ - for (int i = 0; i < persisterArray.length; ++i) { + private void initPersisterList() { + for (int ii = 0; ii < this.persisterArray.length; ++ii) { + String name = (String)this.persisterArray[ii].getProperty("label"); - String name = (String)persisterArray[i].getProperty("label"); + /* + * If someone was sloppy enough to not provide a name, then use the name of the + * class instead. + */ + if (name == null || name.length() == 0) { + name = this.persisterArray[ii].getClass().getName(); + } - // if someone was sloppy enough to not provide a name, then use the - // name of the class instead. - if (name == null || name.length() == 0) - name = persisterArray[i].getClass().getName(); - persisterList.add(name); + this.persisterList.add(name); } } -// private StyledText initDetailPane(Group detailsGroup) { -// StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); -// detailPane.setEditable(false); -// detailPane.getCaret().setVisible(false); -// return detailPane; -// } + /* private StyledText initDetailPane(Group detailsGroup) { + StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); + detailPane.setEditable(false); + detailPane.getCaret().setVisible(false); -// private void updateDetailPane(ServiceReference persister) { -// -// detailPane.setText(""); -// for (int i=0; i<DETAILS_ITEM_KEY.length; i++){ -// String val = (String) persister.getProperty(DETAILS_ITEM_KEY[i]); -// -// StyleRange styleRange = new StyleRange(); -// styleRange.start = detailPane.getText().length(); -// detailPane.append(DETAILS_ITEM_KEY_DISPLAY_VALUE[i] + ":\n"); -// styleRange.length = DETAILS_ITEM_KEY[i].length() + 1; -// styleRange.fontStyle = SWT.BOLD; -// detailPane.setStyleRange(styleRange); -// -// detailPane.append(val + "\n"); -// -// } -// -// } + return detailPane; + }*/ + /* private void updateDetailPane(ServiceReference persister) { + + detailPane.setText(""); + + for (int ii = 0; ii < DETAILS_ITEM_KEY.length; ii++){ + String val = (String)persister.getProperty(DETAILS_ITEM_KEY[ii]); + + StyleRange styleRange = new StyleRange(); + styleRange.start = detailPane.getText().length(); + detailPane.append(DETAILS_ITEM_KEY_DISPLAY_VALUE[ii] + ":\n"); + styleRange.length = DETAILS_ITEM_KEY[ii].length() + 1; + styleRange.fontStyle = SWT.BOLD; + detailPane.setStyleRange(styleRange); + + detailPane.append(val + "\n"); + } + } */ + private void selectionMade(int selectedIndex) { - AlgorithmFactory persister =(AlgorithmFactory) bundleContext.getService(persisterArray[selectedIndex]); - Data[] dataManager = null; + AlgorithmFactory persister = + (AlgorithmFactory)this.bundleContext.getService(this.persisterArray[selectedIndex]); + Data[] data = null; boolean loadSuccess = false; try { - dataManager = new Data[]{new BasicData(selectedFile.getPath(),String.class.getName())}; - dataManager = persister.createAlgorithm(dataManager, null, ciShellContext).execute(); + data = + new Data[] { new BasicData(this.selectedFile.getPath(), String.class.getName()) }; + data = persister.createAlgorithm(data, null, this.ciShellContext).execute(); loadSuccess = true; - } catch (Throwable e) { - this.logger.log(LogService.LOG_ERROR, "Error occurred while executing selection", e); - e.printStackTrace(); + } catch (Throwable exception) { + this.logger.log( + LogService.LOG_ERROR, "Error occurred while executing selection", exception); + exception.printStackTrace(); loadSuccess = false; } - if (dataManager != null && loadSuccess) { - logger.log(LogService.LOG_INFO, "Loaded: "+selectedFile.getPath()); + if ((data != null) && loadSuccess) { + this.logger.log(LogService.LOG_INFO, "Loaded: " + this.selectedFile.getPath()); - for(int i = 0; i<dataManager.length; i++){ - returnList.add(dataManager[i]); + for (int ii = 0; ii < data.length; ii++) { + this.returnList.add(data[ii]); } + close(true); } else { - logger.log(LogService.LOG_ERROR, "Unable to load with selected loader"); + this.logger.log(LogService.LOG_ERROR, "Unable to load with selected loader"); } } @@ -196,9 +222,10 @@ Button select = new Button(parent, SWT.PUSH); select.setText("Select"); select.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - int index = persisterList.getSelectionIndex(); - if(index != -1){ + public void widgetSelected(SelectionEvent selectionEvent) { + int index = FileFormatSelector.this.persisterList.getSelectionIndex(); + + if (index != -1) { selectionMade(index); } } @@ -207,13 +234,13 @@ Button cancel = new Button(parent, SWT.NONE); cancel.setText("Cancel"); cancel.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { + public void widgetSelected(SelectionEvent selectionEvent) { close(false); } }); } public Composite createContent(Composite parent) { - return initGUI(parent); + return initializeGUI(parent); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-11-30 19:31:04
|
Revision: 985 http://cishell.svn.sourceforge.net/cishell/?rev=985&view=rev Author: mwlinnem Date: 2009-11-30 19:30:56 +0000 (Mon, 30 Nov 2009) Log Message: ----------- Added 'model' data type to CIShell (for EpiC). These should probably belong to their specific projects (in this case EpiC), but oh well (it's not as if networks are specifically part of CIShell either really). Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java 2009-11-24 20:05:47 UTC (rev 984) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java 2009-11-30 19:30:56 UTC (rev 985) @@ -43,6 +43,7 @@ private Image databaseIcon; private Image rasterImageIcon; private Image vectorImageIcon; + private Image modelIcon; private Map typeToImageMapping; @@ -73,6 +74,7 @@ databaseIcon = getImage("database.jpg", this.brandPluginID); rasterImageIcon = getImage("raster_image.jpg", this.brandPluginID); vectorImageIcon = getImage("vector_image.jpg", this.brandPluginID); + modelIcon = getImage("model.jpg", this.brandPluginID); typeToImageMapping = new HashMap(); registerImage(DataProperty.OTHER_TYPE, unknownIcon); @@ -93,6 +95,7 @@ registerImage(DataProperty.DATABASE_TYPE, databaseIcon); registerImage(DataProperty.RASTER_IMAGE_TYPE, rasterImageIcon); registerImage(DataProperty.VECTOR_IMAGE_TYPE, vectorImageIcon); + registerImage(DataProperty.MODEL_TYPE, modelIcon); } /** Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java 2009-11-24 20:05:47 UTC (rev 984) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/data/DataProperty.java 2009-11-30 19:30:56 UTC (rev 985) @@ -90,4 +90,7 @@ /** Says this data model is a JPEG object */ public static String RASTER_IMAGE_TYPE = "Raster Image"; + + /** Says this data model is a 'model' object */ + public static String MODEL_TYPE = "Model"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-11-24 20:05:53
|
Revision: 984 http://cishell.svn.sourceforge.net/cishell/?rev=984&view=rev Author: pataphil Date: 2009-11-24 20:05:47 +0000 (Tue, 24 Nov 2009) Log Message: ----------- Committing Patrick's in-progress work, because he's sick and we need to continue with this (Micah). Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-11-23 20:59:28 UTC (rev 983) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-11-24 20:05:47 UTC (rev 984) @@ -11,6 +11,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.net.URI; import java.net.URL; import java.nio.channels.FileChannel; @@ -19,6 +20,7 @@ public class FileUtilities { public static final int READ_TEXT_FILE_BUFFER_SIZE = 1024; + public static final String DEFAULT_STREAM_TO_FILE_NAME = "stream_"; /* * Return a File pointing to the directory specified in @@ -173,6 +175,7 @@ */ public static String extractReaderContents(BufferedReader bufferedReader) throws IOException { StringBuffer contents = new StringBuffer(); + // TODO: Use READ_TEXT_FILE_BUFFER_SIZE as the size instead of 1? char[] readInCharacters = new char[1]; int readCharacterCount = bufferedReader.read(readInCharacters); @@ -241,6 +244,53 @@ return new File(URI.create(fileURL.toString())); } + public static File safeLoadFileFromClasspath(Class clazz, String filePath) throws IOException { + InputStream input = clazz.getResourceAsStream(filePath); + String fileExtension = getFileExtension(filePath); + + return writeEntireStreamToTemporaryFile(input, fileExtension); + } + + public static File writeEntireStreamToTemporaryFile(InputStream stream, String fileExtension) + throws IOException { + return writeEntireStreamToTemporaryFile( + stream, DEFAULT_STREAM_TO_FILE_NAME, fileExtension); + } + + public static File writeEntireStreamToTemporaryFile( + InputStream input, String fileName, String fileExtension) throws IOException { + File temporaryFile = + createTemporaryFileInDefaultTemporaryDirectory(fileName, fileExtension); + OutputStream output = new FileOutputStream(temporaryFile); + // TODO: Use READ_TEXT_FILE_BUFFER_SIZE. + byte[] readCharacters = new byte[1]; + int readCharacterCount = input.read(readCharacters); + + while (readCharacterCount > 0) { + output.write(readCharacters, 0, readCharacterCount); + readCharacterCount = input.read(readCharacters); + } + + output.close(); + input.close(); + + return temporaryFile; + } + + public static String getFileExtension(File file) { + return getFileExtension(file.getAbsolutePath()); + } + + public static String getFileExtension(String filePath) { + int periodPosition = filePath.lastIndexOf("."); + + if ((periodPosition != -1) && ((periodPosition + 1) < filePath.length())) { + return filePath.substring(periodPosition); + } else { + return ""; + } + } + private static File ensureDirectoryExists(String directoryPath) { File directory = new File(directoryPath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2009-11-23 20:59:55
|
Revision: 983 http://cishell.svn.sourceforge.net/cishell/?rev=983&view=rev Author: pataphil Date: 2009-11-23 20:59:28 +0000 (Mon, 23 Nov 2009) Log Message: ----------- * Made FileUtilities.extractReaderContents and FileUtilities.readEntireInputStream. * FileUtilities.readEntireInputStream and FileUtilities.readEntireTextFile now depend on FileUtilities.extractReaderContents. * Reviewed by Micah. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-11-17 19:53:54 UTC (rev 982) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-11-23 20:59:28 UTC (rev 983) @@ -9,6 +9,8 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URI; import java.net.URL; import java.nio.channels.FileChannel; @@ -155,27 +157,33 @@ boolean fileIsEmpty = ( firstLine == null ); return fileIsEmpty; } + + public static String readEntireTextFile(File file) throws IOException { + return extractReaderContents(new BufferedReader(new FileReader(file))); + } + // stream must be guaranteed to end. + public static String readEntireInputStream(InputStream stream) throws IOException { + return extractReaderContents(new BufferedReader(new InputStreamReader(stream))); + } + /* * This is basically copied off of: * http://www.javazoid.com/foj_file.html */ - public static String readEntireTextFile(File file) - throws IOException { - StringBuffer readTextStringBuffer = new StringBuffer(); - BufferedReader fileReader = new BufferedReader( - new FileReader(file)); + public static String extractReaderContents(BufferedReader bufferedReader) throws IOException { + StringBuffer contents = new StringBuffer(); char[] readInCharacters = new char[1]; - int readCharacterCount = fileReader.read(readInCharacters); + int readCharacterCount = bufferedReader.read(readInCharacters); while (readCharacterCount > -1) { - readTextStringBuffer.append(String.valueOf(readInCharacters)); - readCharacterCount = fileReader.read(readInCharacters); + contents.append(String.valueOf(readInCharacters)); + readCharacterCount = bufferedReader.read(readInCharacters); } - fileReader.close(); + bufferedReader.close(); - return readTextStringBuffer.toString(); + return contents.toString(); } public static void copyFile(File sourceFile, File targetFile) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-11-17 19:54:02
|
Revision: 982 http://cishell.svn.sourceforge.net/cishell/?rev=982&view=rev Author: jrbibers Date: 2009-11-17 19:53:54 +0000 (Tue, 17 Nov 2009) Log Message: ----------- Changed the String argument of BasicDataPlus(Object,String,Data) from type to format. This should be more convenient. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java 2009-11-16 20:52:43 UTC (rev 981) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/BasicDataPlus.java 2009-11-17 19:53:54 UTC (rev 982) @@ -45,13 +45,11 @@ /** * * @param inner The object wrapped by this Data. - * @param type The _TYPE constant from {@link DataProperty} - * that best characterizes the type of inner. + * @param format The format of inner (like a MIME type, file extension, or class name). * @param parent The parent of inner. */ - public BasicDataPlus(Object inner, String type, Data parent) { - this(inner); - setType(type); + public BasicDataPlus(Object inner, String format, Data parent) { + this(inner, format); setParent(parent); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-11-16 20:52:59
|
Revision: 981 http://cishell.svn.sourceforge.net/cishell/?rev=981&view=rev Author: jrbibers Date: 2009-11-16 20:52:43 +0000 (Mon, 16 Nov 2009) Log Message: ----------- Synchronized the getTempDirectory method for thread safety. I had been having trouble with running static executable algorithms in parallel and traced the problem here. Presumably multiple threads were attempting to run through the delete and mkdirs calls concurrently. Modified Paths: -------------- trunk/templates/org.cishell.templates/src/org/cishell/templates/Activator.java Modified: trunk/templates/org.cishell.templates/src/org/cishell/templates/Activator.java =================================================================== --- trunk/templates/org.cishell.templates/src/org/cishell/templates/Activator.java 2009-11-12 22:16:19 UTC (rev 980) +++ trunk/templates/org.cishell.templates/src/org/cishell/templates/Activator.java 2009-11-16 20:52:43 UTC (rev 981) @@ -61,7 +61,7 @@ dir.delete(); } - public static File getTempDirectory() { + public synchronized static File getTempDirectory() { if (tempDirectory == null) { try { tempDirectory = File.createTempFile("CIShell-Session-", ""); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jrb...@us...> - 2009-11-12 22:16:29
|
Revision: 980 http://cishell.svn.sourceforge.net/cishell/?rev=980&view=rev Author: jrbibers Date: 2009-11-12 22:16:19 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Fixed FileUtilities.loadFileFromClassPath compatibility issue and used it in compartmental model conversion tester. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-11-06 21:32:45 UTC (rev 979) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/FileUtilities.java 2009-11-12 22:16:19 UTC (rev 980) @@ -9,7 +9,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import java.net.URISyntaxException; +import java.net.URI; import java.net.URL; import java.nio.channels.FileChannel; @@ -227,11 +227,10 @@ } } - public static File loadFileFromClassPath(Class clazz, String filePath) - throws URISyntaxException { + public static File loadFileFromClassPath(Class clazz, String filePath) { URL fileURL = clazz.getResource(filePath); - return new File(fileURL.toURI()); + return new File(URI.create(fileURL.toString())); } private static File ensureDirectoryExists(String directoryPath) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-11-06 21:33:06
|
Revision: 979 http://cishell.svn.sourceforge.net/cishell/?rev=979&view=rev Author: mwlinnem Date: 2009-11-06 21:32:45 +0000 (Fri, 06 Nov 2009) Log Message: ----------- Explicitly created Integers instead of relying on auto-boxing, so CIShell stays 1.4 compatible (build breaks if it isn't). Modified Paths: -------------- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java Modified: trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java =================================================================== --- trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java 2009-11-06 20:53:24 UTC (rev 978) +++ trunk/core/org.cishell.algorithm.convertergraph/src/org/cishell/algorithm/convertergraph/ConverterGraphComputation.java 2009-11-06 21:32:45 UTC (rev 979) @@ -122,7 +122,7 @@ .equalsIgnoreCase(currentNodeKey)) { int currentVertexStrength = ((Integer) currentVertex.getUserDatum("strength")).intValue(); - currentVertex.setUserDatum("strength", ++currentVertexStrength, + currentVertex.setUserDatum("strength", new Integer(++currentVertexStrength), new UserDataContainer.CopyAction.Shared()); return currentVertex; } @@ -134,8 +134,7 @@ nodeCount++; Vertex node = new DirectedSparseVertex(); - - node.addUserDatum("strength", 1, new UserDataContainer.CopyAction.Shared()); + node.addUserDatum("strength", new Integer(1), new UserDataContainer.CopyAction.Shared()); node.addUserDatum("label", nodeKey, new UserDataContainer.CopyAction.Shared()); outputGraph.addVertex(node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2009-11-06 20:53:37
|
Revision: 978 http://cishell.svn.sourceforge.net/cishell/?rev=978&view=rev Author: mwlinnem Date: 2009-11-06 20:53:24 +0000 (Fri, 06 Nov 2009) Log Message: ----------- Added convertergraph (was in feature before, but not releng, which caused the build to fail). Modified Paths: -------------- trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml Modified: trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml =================================================================== --- trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2009-11-05 20:59:55 UTC (rev 977) +++ trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2009-11-06 20:53:24 UTC (rev 978) @@ -90,6 +90,7 @@ <param name="project.name" value="/deployment/org.cishell.reference.gui.feature"/> <param name="url" value="https://cishell.svn.sourceforge.net/svnroot/cishell/trunk"/> </antcall> + <antcall target="svn.co"> <param name="target" value="features"/> <param name="element.id" value="org.cishell.reference.gui.brand.feature"/> @@ -150,6 +151,12 @@ <param name="project.name" value="/clients/gui/org.cishell.reference.gui.scheduler"/> <param name="url" value="https://cishell.svn.sourceforge.net/svnroot/cishell/trunk"/> </antcall> + <antcall target="svn.co"> + <param name="target" value="plugins"/> + <param name="element.id" value="org.cishell.algorithm.convertergraph"/> + <param name="project.name" value="org.cishell.algorithm.convertergraph"/> + <param name="url" value="https://cishell.svn.sourceforge.net/svnroot/cishell/trunk/core/"/> + </antcall> <antcall target="svn.co"> <param name="target" value="plugins"/> <param name="element.id" value="org.prefuse.lib"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |