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: <pat...@us...> - 2010-08-23 18:06:46
|
Revision: 1127 http://cishell.svn.sourceforge.net/cishell/?rev=1127&view=rev Author: pataphil Date: 2010-08-23 18:06:40 +0000 (Mon, 23 Aug 2010) Log Message: ----------- * Added MapUtilities.keysToCounts(). * Reviewed by Chintan. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java 2010-08-19 17:08:12 UTC (rev 1126) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java 2010-08-23 18:06:40 UTC (rev 1127) @@ -6,7 +6,6 @@ import java.util.Iterator; public class CollectionUtilities { - /* Return only elements of the Collection which are mapped to true in the * Dictionary */ Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-08-19 17:08:12 UTC (rev 1126) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MapUtilities.java 2010-08-23 18:06:40 UTC (rev 1127) @@ -77,4 +77,18 @@ return values; } + + public static<K> Map<K, Integer> keysToCounts(Collection<K> keys) { + Map<K, Integer> keysToCounts = new HashMap<K, Integer>(); + + for (K key : keys) { + if (keysToCounts.containsKey(key)) { + keysToCounts.put(key, keysToCounts.get(key) + 1); + } else { + keysToCounts.put(key, 1); + } + } + + return keysToCounts; + } } \ 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: <pat...@us...> - 2010-08-19 17:08:19
|
Revision: 1126 http://cishell.svn.sourceforge.net/cishell/?rev=1126&view=rev Author: pataphil Date: 2010-08-19 17:08:12 +0000 (Thu, 19 Aug 2010) Log Message: ----------- * AlgorithmFactories can now gracefully fail in mutateParameters() and gracefully cancel/fail in createAlgorithm(). * Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-18 20:39:52 UTC (rev 1125) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-19 17:08:12 UTC (rev 1126) @@ -26,6 +26,8 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmCanceledException; +import org.cishell.framework.algorithm.AlgorithmCreationCanceledException; +import org.cishell.framework.algorithm.AlgorithmCreationFailedException; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; @@ -100,7 +102,7 @@ } boolean inputIsValid = testDataValidityIfPossible(factory, data); - + if (!inputIsValid) { return null; } @@ -108,13 +110,28 @@ // Create algorithm parameters. String metatypePID = getMetaTypeID(serviceReference); - MetaTypeProvider provider = - getPossiblyMutatedMetaTypeProvider(metatypePID, pid, factory); + // TODO: Refactor this. + MetaTypeProvider provider = null; + + try { + provider = getPossiblyMutatedMetaTypeProvider(metatypePID, pid, factory); + } catch (AlgorithmCreationFailedException e) { + String format = + "An error occurred when creating the algorithm \"%s\" with the data you " + + "provided. (Reason: %s)"; + String logMessage = String.format( + format, + serviceReference.getProperty(AlgorithmProperty.LABEL), + e.getMessage()); + log(LogService.LOG_WARNING, logMessage, e); + + return null; + } Dictionary<String, Object> parameters = getUserEnteredParameters(metatypePID, provider); - // Check to see if the user cancelled the operation. + // Check to see if the user canceled the operation. if (parameters == null) { return null; } @@ -184,13 +201,31 @@ Data[] data, Dictionary<String, Object> parameters, CIShellContext ciContext) { + final String algorithmName = + (String) serviceReference.getProperty(AlgorithmProperty.LABEL); // TODO: Call on algorithm invocation service here. try { return factory.createAlgorithm(data, parameters, ciContext); + } catch (AlgorithmCreationCanceledException e) { + String logMessage = String.format( + "The algorithm \"%s\" was canceled by the user.", + algorithmName, + e.getMessage()); + log(LogService.LOG_WARNING, logMessage, e); + + return null; + } catch (AlgorithmCreationFailedException e) { + String format = "An error occurred when creating algorithm \"%s\". (Reason: %s)"; + String errorMessage = String.format(format, algorithmName, e.getMessage()); + GUIBuilderService builder = + (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + builder.showError("Error!", errorMessage, e); + log(LogService.LOG_ERROR, errorMessage, e); + + return null; } catch (Exception e) { - String errorMessage = - "Unexpected error occurred while creating algorithm " + " \"" + - serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\""; + String errorMessage = String.format( + "Unexpected error occurred while creating algorithm \"%s\".", algorithmName); GUIBuilderService builder = (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); // TODO: This is where uncaught exceptions are displayed. @@ -244,7 +279,7 @@ outData = algorithm.execute(); } catch (AlgorithmCanceledException e) { String logMessage = String.format( - "The algorithm: \"%s\" was canceled by the user. (Reason: %s)", + "The algorithm: \"%s\" was canceled by the user.", algorithmName, e.getMessage()); log(LogService.LOG_WARNING, logMessage, e); @@ -327,7 +362,8 @@ } protected MetaTypeProvider getPossiblyMutatedMetaTypeProvider( - String metatypePID, String pid, AlgorithmFactory factory) { + String metatypePID, String pid, AlgorithmFactory factory) + throws AlgorithmCreationFailedException { MetaTypeProvider provider = null; MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); @@ -335,18 +371,21 @@ provider = metaTypeService.getMetaTypeInformation(serviceReference.getBundle()); } - if (factory instanceof ParameterMutator && provider != null) { + if ((factory instanceof ParameterMutator) && (provider != null)) { try { - ObjectClassDefinition ocd = - provider.getObjectClassDefinition(metatypePID, null); - if (ocd == null) logNullOCDWarning(pid, metatypePID); + ObjectClassDefinition ocd = provider.getObjectClassDefinition(metatypePID, null); + + if (ocd == null) { + logNullOCDWarning(pid, metatypePID); + } + ocd = ((ParameterMutator) factory).mutateParameters(data, ocd); + if (ocd != null) { provider = new BasicMetaTypeProvider(ocd); } } catch (IllegalArgumentException e) { - log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " - + metatypePID, e); + log(LogService.LOG_DEBUG, pid + " has an invalid metatype id: " + metatypePID, e); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-18 20:39:59
|
Revision: 1125 http://cishell.svn.sourceforge.net/cishell/?rev=1125&view=rev Author: pataphil Date: 2010-08-18 20:39:52 +0000 (Wed, 18 Aug 2010) Log Message: ----------- * Style cleanup. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCanceledException.java trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/Converter.java trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterPath.java trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/DefaultTestRunner.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 2010-08-18 20:38:51 UTC (rev 1124) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2010-08-18 20:39:52 UTC (rev 1125) @@ -24,6 +24,7 @@ import org.cishell.app.service.datamanager.DataManagerListener; import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmCanceledException; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.Data; @@ -501,11 +502,14 @@ e.printStackTrace(); } else { AbstractDataManagerView.this.logger = Activator.getLogService(); - AbstractDataManagerView.this.logger.log( - LogService.LOG_ERROR, - "org.cishell.framework.algorithm.AlgorithmExecutionException", - e); - e.printStackTrace(); + + if (AbstractDataManagerView.this.logger != null) { + AbstractDataManagerView.this.logger.log( + LogService.LOG_ERROR, + "org.cishell.framework.algorithm.AlgorithmExecutionException", + e); + e.printStackTrace(); + } } } } @@ -522,11 +526,17 @@ try { algorithm.execute(); } catch (AlgorithmExecutionException e) { - if (logger != null) { - logger.log(LogService.LOG_ERROR, e.getMessage(), e); + if (AbstractDataManagerView.this.logger != null) { + AbstractDataManagerView.this.logger.log( + LogService.LOG_ERROR, e.getMessage(), e); } else { - logger = Activator.getLogService(); - logger.log(LogService.LOG_ERROR, e.getMessage(), e); + AbstractDataManagerView.this.logger = Activator.getLogService(); + + // TODO: Find occurrences of this crap happening, and make it a method. + if (AbstractDataManagerView.this.logger != null) { + AbstractDataManagerView.this.logger.log( + LogService.LOG_ERROR, e.getMessage(), e); + } } e.printStackTrace(); Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCanceledException.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCanceledException.java 2010-08-18 20:38:51 UTC (rev 1124) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCanceledException.java 2010-08-18 20:39:52 UTC (rev 1125) @@ -1,6 +1,6 @@ package org.cishell.framework.algorithm; -public class AlgorithmCanceledException extends Exception { +public class AlgorithmCanceledException extends RuntimeException { private static final long serialVersionUID = 9017277008277139930L; public AlgorithmCanceledException(String message, Throwable exception) { Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2010-08-18 20:38:51 UTC (rev 1124) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/service/conversion/ConverterImpl.java 2010-08-18 20:39:52 UTC (rev 1125) @@ -33,20 +33,18 @@ import org.osgi.service.metatype.MetaTypeProvider; public class ConverterImpl implements Converter, AlgorithmFactory, AlgorithmProperty { - private ServiceReference[] refs; + private ServiceReference[] serviceReferences; private BundleContext bContext; - private Dictionary properties; + private Dictionary<String, Object> properties; private CIShellContext ciContext; public ConverterImpl(BundleContext bContext, CIShellContext ciContext, ServiceReference[] refs) { this.bContext = bContext; this.ciContext = ciContext; - this.refs = refs; + this.serviceReferences = refs; + properties = new Hashtable<String, Object>(); - - properties = new Hashtable(); - properties.put(IN_DATA, refs[0].getProperty(IN_DATA)); properties.put(OUT_DATA, refs[refs.length-1].getProperty(OUT_DATA)); properties.put(LABEL, properties.get(IN_DATA) + " -> " + properties.get(OUT_DATA)); @@ -109,7 +107,7 @@ * @see org.cishell.service.conversion.Converter#getConverterChain() */ public ServiceReference[] getConverterChain() { - return refs; + return this.serviceReferences; } /** @@ -134,25 +132,27 @@ } public String toString() { - String str =""; - for (int j = 0; j < refs.length; ++j) { - str += refs[j].getProperty(Constants.SERVICE_ID); + String str = ""; + + for (ServiceReference serviceReference : this.serviceReferences) { + str += serviceReference.getProperty(Constants.SERVICE_ID); str += " "; - str += refs[j].getProperty(Constants.SERVICE_PID); + str += serviceReference.getProperty(Constants.SERVICE_PID); str += "-> "; } return str; } - public boolean equals(Object o) { + public boolean equals(Object compareTo) { boolean equal = false; - if (o instanceof Converter) { - ServiceReference[] otherServiceReference = - ((Converter) o).getConverterChain(); - if (refs.length == otherServiceReference.length) { + + if (compareTo instanceof Converter) { + ServiceReference[] otherServiceReference = ((Converter) compareTo).getConverterChain(); + + if (this.serviceReferences.length == otherServiceReference.length) { for (int i = 0; i < otherServiceReference.length; i++) { - if (refs[i].getProperty(Constants.SERVICE_ID).equals( + if (this.serviceReferences[i].getProperty(Constants.SERVICE_ID).equals( otherServiceReference[i].getProperty( Constants.SERVICE_ID))) { equal = true; @@ -167,7 +167,7 @@ return equal; } - /* The conversion chain (refs) is lossless + /* The conversion chain (serviceReferences) is lossless * if and only if no conversion (ref) is lossy. */ private String calculateLossiness(ServiceReference[] refs) { @@ -186,62 +186,61 @@ public static final String MIME_TYPE_PREFIX = "file:"; private Data[] inData; - private Dictionary parameters; - private CIShellContext context; - private LogService log; + private Dictionary<String, Object> parameters; + private CIShellContext ciShellContext; + private LogService logger; - public ConverterAlgorithm(Data[] inData, - Dictionary parameters, - CIShellContext context) { + public ConverterAlgorithm( + Data[] inData, Dictionary<String, Object> parameters, CIShellContext ciShellContext) { this.inData = inData; this.parameters = parameters; - this.context = context; - this.log = - (LogService) context.getService(LogService.class.getName()); + this.ciShellContext = ciShellContext; + this.logger = + (LogService) ciShellContext.getService(LogService.class.getName()); } public Data[] execute() throws AlgorithmExecutionException { - Data[] convertedData = inData; + Data[] convertedData = this.inData; - // For each converter in the converter chain (refs) - for (int ii = 0; ii < refs.length; ii++) { + // For each converter in the converter chain (serviceReferences) + for (int ii = 0; ii < serviceReferences.length; ii++) { AlgorithmFactory factory = - (AlgorithmFactory) bContext.getService(refs[ii]); + (AlgorithmFactory) bContext.getService(serviceReferences[ii]); if (factory != null) { - Algorithm alg = - factory.createAlgorithm(convertedData, parameters, context); + Algorithm algorithm = factory.createAlgorithm( + convertedData, this.parameters, this.ciShellContext); try { - convertedData = alg.execute(); + convertedData = algorithm.execute(); } catch(AlgorithmExecutionException e) { - boolean isLastStep = (ii == refs.length - 1); - if (isLastStep && isHandler(refs[ii])) { + boolean isLastStep = (ii == serviceReferences.length - 1); + if (isLastStep && isHandler(serviceReferences[ii])) { /* If the last step of the converter chain is a * handler and it is the first (and so only) step - * to fail, just log a warning and return the + * to fail, just logger a warning and return the * un-handled data. */ String warningMessage = "Warning: Attempting to convert data without " + "validating the output since the validator failed " + "with this problem:\n " - + createErrorMessage(refs[ii], e); + + createErrorMessage(serviceReferences[ii], e); - log.log(LogService.LOG_WARNING, warningMessage, e); + this.logger.log(LogService.LOG_WARNING, warningMessage, e); return convertedData; } else { throw new AlgorithmExecutionException( - createErrorMessage(refs[ii], e), e); + createErrorMessage(serviceReferences[ii], e), e); } } } else { throw new AlgorithmExecutionException( "Missing subconverter: " - + refs[ii].getProperty(Constants.SERVICE_PID)); + + serviceReferences[ii].getProperty(Constants.SERVICE_PID)); } } @@ -286,7 +285,7 @@ return "Problem converting data from " + prettifyDataType(inType) + " to " + prettifyDataType(outType) - + " (See the log file for more details).:\n " + + " (See the logger file for more details).:\n " + e.getMessage(); } else { @@ -296,7 +295,7 @@ + " during the necessary intermediate conversion from " + prettifyDataType(preProblemType) + " to " + prettifyDataType(postProblemType) - + " (See the log file for more details):\n " + + " (See the logger file for more details):\n " + e.getMessage(); } } Modified: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/Converter.java =================================================================== --- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/Converter.java 2010-08-18 20:38:51 UTC (rev 1124) +++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/Converter.java 2010-08-18 20:39:52 UTC (rev 1125) @@ -12,31 +12,29 @@ import org.osgi.framework.ServiceReference; public class Converter { + private BundleContext bundleContext; + private ServiceReference serviceReference; - private BundleContext bContext; - - private ServiceReference ref; - - public Converter(BundleContext bContext, ServiceReference ref) { - this.bContext = bContext; - this.ref = ref; + public Converter(BundleContext bundleContext, ServiceReference serviceReference) { + this.bundleContext = bundleContext; + this.serviceReference = serviceReference; } public ServiceReference getServiceReference() { - return this.ref; + return this.serviceReference; } - public ServiceReference getRef() { - return this.ref; + public ServiceReference getServieReference() { + return this.serviceReference; } public boolean isLossy() { - String conversion = (String) - ref.getProperty(AlgorithmProperty.CONVERSION); + String conversion = + (String) this.serviceReference.getProperty(AlgorithmProperty.CONVERSION); if (conversion == null) { return false; - //if lossiness is not defined, assume it is not lossy. + // If lossiness is not defined, assume it is not lossy. } if (conversion.equals(AlgorithmProperty.LOSSY)) { @@ -44,17 +42,17 @@ } else if (conversion.equals(AlgorithmProperty.LOSSLESS)) { return false; } else { - //assuming lossy by default + // Assuming lossy by default. return true; } } public String getInData() { - return (String) ref.getProperty(AlgorithmProperty.IN_DATA); + return (String) this.serviceReference.getProperty(AlgorithmProperty.IN_DATA); } public String getOutData() { - return (String) ref.getProperty(AlgorithmProperty.OUT_DATA); + return (String) this.serviceReference.getProperty(AlgorithmProperty.OUT_DATA); } public String getShortName() { @@ -62,23 +60,22 @@ } public String getUniqueName() { - return (String) this.ref.getProperty("service.pid"); + return (String) this.serviceReference.getProperty("service.pid"); } public String toString() { return getUniqueName(); } - public Data[] execute(Data[] input, Hashtable parameters, - CIShellContext cContext) throws AlgorithmExecutionException { + public Data[] execute( + Data[] input, Hashtable<String, Object> parameters, CIShellContext ciShellContext) + throws AlgorithmExecutionException { + + AlgorithmFactory converterFactory = + (AlgorithmFactory) this.bundleContext.getService(this.serviceReference); + Algorithm converter = converterFactory.createAlgorithm(input, parameters, ciShellContext); + Data[] output = converter.execute(); - AlgorithmFactory convAlgFactory = - (AlgorithmFactory) this.bContext.getService(this.ref); - Algorithm convAlg = convAlgFactory.createAlgorithm(input, parameters, - cContext); - - Data[] output = convAlg.execute(); - return output; } Modified: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterPath.java =================================================================== --- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterPath.java 2010-08-18 20:38:51 UTC (rev 1124) +++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterPath.java 2010-08-18 20:39:52 UTC (rev 1125) @@ -9,87 +9,74 @@ import org.osgi.service.log.LogService; public class ConverterPath implements AlgorithmProperty { + private LogService logger; + private String inData = null; + private String outData = null; + private List<Converter> path; - private BundleContext bContext; - private LogService log; - private String in_data = null; - private String out_data = null; - - private List path; - - public ConverterPath(BundleContext bContext, LogService log){ - this.bContext = bContext; - this.log = log; - - path = new ArrayList(); + public ConverterPath(BundleContext bundleContext, LogService logger){ + this.logger = logger; + this.path = new ArrayList<Converter>(); } - public ConverterPath(ConverterPath p, BundleContext bContext) { - this.bContext = bContext; - - in_data = p.getInData(); - out_data = p.getOutData(); + public ConverterPath(ConverterPath path, BundleContext bundleContext) { + this.inData = path.getInData(); + this.outData = path.getOutData(); + this.path = new ArrayList<Converter>(path.getPath()); - this.path = new ArrayList(p.getPath()); - } - public void setInData(String s){ - - this.in_data = s; + public void setInData(String inData) { + this.inData = inData; } - public void setOutData(String s){ - - this.out_data = s; + public void setOutData(String outData) { + this.outData = outData; } - public boolean add(Converter c){ - - boolean val = true; - - if(path.contains(c)){ + public boolean add(Converter converter) { + if (path.contains(converter)) { return false; + } else { + path.add(converter); + this.setOutData(converter.getOutData()); + + return true; } - - path.add(c); - this.setOutData(c.getOutData()); - return val; } - public String getInData(){ - - return this.in_data; + public String getInData() { + return this.inData; } - public String getOutData(){ - - return this.out_data; + public String getOutData() { + return this.outData; } public String getAcceptedFileFormat() { if (size() > 0) { - return (String) getRef(0).getProperty(AlgorithmProperty.OUT_DATA); + return (String) getServiceReference(0).getProperty(AlgorithmProperty.OUT_DATA); } else { - this.log.log(LogService.LOG_ERROR, "Converter Path cannot " + + this.logger.log(LogService.LOG_ERROR, "Converter Path cannot " + "determine accepted file format if there are no " + "converters inside it. Returning null String."); + return ""; } } - public List getPath(){ - + public List<Converter> getPath() { return this.path; } - //inclusive - public List getPathUpTo(Converter upToConv) { + /// Inclusive. + public List<Converter> getPathUpTo(Converter upToConverter) { int convIndex = -1; + for (int ii = 0; ii < this.path.size(); ii++) { Converter aConvInPath = get(ii); - if (aConvInPath.equals(upToConv)) { + if (aConvInPath.equals(upToConverter)) { convIndex = ii; break; } @@ -108,50 +95,40 @@ return (Converter) this.path.get(index); } - public ServiceReference getRef(int index) { + public ServiceReference getServiceReference(int index) { + Converter converter = this.path.get(index); + ServiceReference serviceReference = converter.getServieReference(); - Converter c = (Converter) this.path.get(index); - ServiceReference ref = c.getRef(); - return ref; + return serviceReference; } - public Converter[] getPathAsArray(){ - + public Converter[] getPathAsArray() { return (Converter[]) this.path.toArray(new Converter[0]); } public boolean isLossy() { - - String lossiness = LOSSLESS; - for (int i = 0; i < this.path.size(); i++) { - Converter c = (Converter) this.path.get(i); - - if (c.isLossy()) { - lossiness = LOSSY; + for (Converter converter : this.path) { + if (converter.isLossy()) { + return true; } } - boolean result = lossiness.equals(LOSSY); - return result; + return false; } public boolean preservesIDs() { - - //TODO: Determine this somehow. + // TODO: Determine this somehow. return false; } public int size() { - return this.path.size(); } - public boolean containsConverterNamed(String convName) { - for (int ii = 0; ii < this.path.size(); ii++) { - Converter conv = (Converter) this.path.get(ii); - - if (conv.getShortName().equals(convName) || - conv.getUniqueName().equals(convName)) { + public boolean containsConverterNamed(String converterName) { + for (Converter converter : this.path) { + if (converter.getShortName().equals(converterName) || + converter.getUniqueName().equals(converterName)) { return true; } } @@ -160,6 +137,6 @@ } public String getConverterName(int index) { - return (String) get(index).getUniqueName(); + return get(index).getUniqueName(); } } Modified: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/DefaultTestRunner.java =================================================================== --- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/DefaultTestRunner.java 2010-08-18 20:38:51 UTC (rev 1124) +++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/tester2/DefaultTestRunner.java 2010-08-18 20:39:52 UTC (rev 1125) @@ -28,43 +28,38 @@ import prefuse.data.Graph; +// TODO: Continue refactoring this. public class DefaultTestRunner implements TestRunner { + private LogService logger; - private LogService log; - - public DefaultTestRunner(LogService log) { - this.log = log; + public DefaultTestRunner(LogService logger) { + this.logger = logger; } public FilePassResult[] runTest(TestConfigData testData) { - Data[][] testFileData = testData.getTestFileData(); ConverterPath testConverters = testData.getTestConverters(); - ConverterPath comparisonConverters = testData - .getComparisonConverters(); - - List testResults = new ArrayList(); + ConverterPath comparisonConverters = testData.getComparisonConverters(); + List<FilePassResult> testResults = new ArrayList<FilePassResult>(); - for (int ii = 0; ii < testFileData.length; ii++) { - Data[] originalFileData = testFileData[ii]; - - // test conversion phase + for (Data[] originalFileData : testFileData) { + // Test conversion phase. - ConvertResult testPhaseResult = convert(originalFileData, - testConverters, testData); - + ConvertResult testPhaseResult = convert(originalFileData, testConverters, testData); Data[][] allDataFromTestPhase = testPhaseResult.getAllData(); if (!testPhaseResult.succeeded()) { - FilePassFailure failure = createFailResult(originalFileData, - PassPhase.TEST_CONV_PHASE, - testPhaseResult.getFailInfo(), + FilePassFailure failure = createFailResult( + originalFileData, + PassPhase.TEST_CONV_PHASE, + testPhaseResult.getFailInfo(), allDataFromTestPhase, null, null); testResults.add(failure); continue; } + Data[] resultFileData = testPhaseResult.getResult(); @@ -144,9 +139,8 @@ ConverterPath converters, TestConfigData testData) { Data[] currentData = getFilePathData(startData); + List<Data[]> dataSoFar = new ArrayList<Data[]>(); - List dataSoFar = new ArrayList(); - // if (startData != null) { // alterMetaData(startData); // dataSoFar.add(startData); @@ -156,7 +150,7 @@ * rig up fake CIShellContext so we can get ahold of * errors sent to logger. */ - FakeLogCIShellContext fakeCContext = + FakeLogCIShellContext fakeCIShellContext = new FakeLogCIShellContext(testData.getContext()); @@ -168,14 +162,15 @@ for (int ii = 0; ii < converters.size(); ii++) { currentConverter = converters.get(ii); - Hashtable parameters = new Hashtable(); //no parameters used + // No parameters used. + Hashtable<String, Object> parameters = new Hashtable<String, Object>(); - currentData = currentConverter.execute(currentData, - parameters, fakeCContext); + currentData = + currentConverter.execute(currentData, parameters, fakeCIShellContext); if (currentData != null) { - setMetaData(currentData, currentConverter); - dataSoFar.add(currentData); + setMetadata(currentData, currentConverter); + dataSoFar.add(currentData); } /* @@ -191,9 +186,9 @@ String explanation = "Result of conversion was null. \r\n"; - if (fakeCContext.hasLogEntries()) { - String logText = extractLogText(fakeCContext); - explanation += "Error log contains the following: \r\n" + + if (fakeCIShellContext.hasLogEntries()) { + String logText = extractLogText(fakeCIShellContext); + explanation += "Error logger contains the following: \r\n" + logText; } else { explanation += "No errors logged. Cause unknown. \r\n"; @@ -202,19 +197,24 @@ ConvFailureInfo failInfo = new ConvFailureInfo( explanation, converter); - ConvertResult result = new ConvertResult(failInfo, (Data[][]) dataSoFar.toArray(new Data[dataSoFar.size()][])); + ConvertResult result = new ConvertResult( + failInfo, (Data[][]) dataSoFar.toArray(new Data[dataSoFar.size()][])); + return result; } } } catch (Throwable t) { - ConvFailureInfo failInfo = new ConvFailureInfo(getStackTrace(t), - currentConverter); - ConvertResult result = new ConvertResult(failInfo,(Data[][]) dataSoFar.toArray(new Data[dataSoFar.size()][])); + ConvFailureInfo failInfo = new ConvFailureInfo(getStackTrace(t), currentConverter); + ConvertResult result = new ConvertResult( + failInfo,(Data[][]) dataSoFar.toArray(new Data[dataSoFar.size()][])); + return result; } Data[] resultData = currentData; - ConvertResult result = new ConvertResult(resultData,(Data[][]) dataSoFar.toArray(new Data[dataSoFar.size()][])); + ConvertResult result = new ConvertResult( + resultData,(Data[][]) dataSoFar.toArray(new Data[dataSoFar.size()][])); + return result; } @@ -288,7 +288,7 @@ Data result = new BasicData(filePath, format); return new Data[] { result }; } catch (IOException e) { - this.log.log(LogService.LOG_ERROR, "Could not get file path " + + this.logger.log(LogService.LOG_ERROR, "Could not get file path " + "from file " + actualFile, e); return null; } @@ -316,51 +316,49 @@ return logText; } - private void setMetaData(Data[] data, Converter converter) { - if (data == null || data.length < 1) { + private void setMetadata(Data[] data, Converter converter) { + if ((data == null) || (data.length < 1)) { return; } Data datum = data[0]; - Dictionary md = datum.getMetadata(); - if (md.get(DataProperty.LABEL) == null) { - md.put(DataProperty.LABEL, "result of " + converter.getShortName()); + Dictionary<String, Object> metadata = datum.getMetadata(); + + if (metadata.get(DataProperty.LABEL) == null) { + metadata.put(DataProperty.LABEL, "result of " + converter.getShortName()); } else { - alterMetaData(data); - md.put(DataProperty.LABEL, md.get(DataProperty.LABEL) + ": result of " + converter.getShortName()); + alterMetadata(data); + metadata.put( + DataProperty.LABEL, + metadata.get(DataProperty.LABEL) + ": result of " + converter.getShortName()); } } private String getFileName(String fileLabel) { - - //index variables will be -1 if index is not found. + // Index variables will be -1 if index is not found. int descriptionEndIndex = fileLabel.lastIndexOf(":"); int filePathEndIndex = fileLabel.lastIndexOf(File.separator); - //doesn't matter if either variable is -1, since startIndex will be - //zero and none of the string will be cut off the front. + /* Doesn't matter if either variable is -1, since startIndex will be zero and none of the + * string will be cut off the front. + */ int startIndex = Math.max(descriptionEndIndex, filePathEndIndex) + 1; - String fileNameWithExtension = fileLabel.substring(startIndex); - - - - int endIndex = fileNameWithExtension.length(); // don't cut any off the end. - - + int endIndex = fileNameWithExtension.length(); // Don't cut any off the end. String fileNameWithoutExtension = fileNameWithExtension.substring(0, endIndex); - String fileName = fileNameWithoutExtension; + return fileName; } - private void alterMetaData(Data[] origFileData) { - Data data = origFileData[0]; - Dictionary metadata = data.getMetadata(); + private void alterMetadata(Data[] originalFileData) { + Data data = originalFileData[0]; + Dictionary<String, Object> metadata = data.getMetadata(); String label = (String) metadata.get(DataProperty.LABEL); + if (label != null) { - metadata.put(DataProperty.LABEL, getFileName(label)); + metadata.put(DataProperty.LABEL, getFileName(label)); } else { metadata.put(DataProperty.LABEL, "null"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-18 20:38:57
|
Revision: 1124 http://cishell.svn.sourceforge.net/cishell/?rev=1124&view=rev Author: pataphil Date: 2010-08-18 20:38:51 +0000 (Wed, 18 Aug 2010) Log Message: ----------- * Added handling for AlgorithmCanceledException, so Algorithms can (optionally) cancel out without the user seeing an awful error message box. * Reviewed by Micah. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-12 16:14:56 UTC (rev 1123) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-18 20:38:51 UTC (rev 1124) @@ -25,6 +25,7 @@ import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmCanceledException; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; @@ -236,19 +237,30 @@ protected Data[] tryExecutingAlgorithm(Algorithm algorithm) { Data[] outData = null; + final String algorithmName = + (String) serviceReference.getProperty(AlgorithmProperty.LABEL); + try { outData = algorithm.execute(); + } catch (AlgorithmCanceledException e) { + String logMessage = String.format( + "The algorithm: \"%s\" was canceled by the user. (Reason: %s)", + algorithmName, + e.getMessage()); + log(LogService.LOG_WARNING, logMessage, e); } catch (AlgorithmExecutionException e) { - log(LogService.LOG_ERROR, "The Algorithm: \"" - + serviceReference.getProperty(AlgorithmProperty.LABEL) - + "\" had an error while executing: " + e.getMessage(), e); + String logMessage = String.format( + "The algorithm: \"%s\" had an error while executing: %s", + algorithmName, + e.getMessage()); + log(LogService.LOG_ERROR, logMessage, e); } catch (RuntimeException e) { - GUIBuilderService builder = (GUIBuilderService) - ciShellContext.getService(GUIBuilderService.class.getName()); - - builder.showError("Error!", - "An unexpected exception occurred while " + "executing \"" - + serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\"", e); + GUIBuilderService builder = + (GUIBuilderService) ciShellContext.getService(GUIBuilderService.class.getName()); + String errorMessage = String.format( + "An unxpected error occurred while executing the algorithm \"%s\".", + algorithmName); + builder.showError("Error!", errorMessage, e); } return outData; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-12 16:15:02
|
Revision: 1123 http://cishell.svn.sourceforge.net/cishell/?rev=1123&view=rev Author: pataphil Date: 2010-08-12 16:14:56 +0000 (Thu, 12 Aug 2010) Log Message: ----------- * Added MutateParameterUtilities.formLabelAttributeDefinition * Reviewed by Patrick Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java 2010-08-06 16:58:57 UTC (rev 1122) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/MutateParameterUtilities.java 2010-08-12 16:14:56 UTC (rev 1123) @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Map; +import java.util.List; import org.cishell.reference.service.metatype.BasicObjectClassDefinition; import org.cishell.utilities.mutateParameter.AttributeDefinitionTransformer; @@ -24,15 +25,35 @@ public static AttributeDefinition formLabelAttributeDefinition( AttributeDefinition oldAttributeDefinition, Table table) throws ColumnNotFoundException { - Collection<String> validStringColumnsInTable = + Collection<String> originalLabelColumnNames = Arrays.asList(TableUtilities.getValidStringColumnNamesInTable(table)); AttributeDefinition labelAttributeDefinition = cloneToDropdownAttributeDefinition( - oldAttributeDefinition, validStringColumnsInTable, validStringColumnsInTable); + oldAttributeDefinition, originalLabelColumnNames, originalLabelColumnNames); return labelAttributeDefinition; } + + /** + * Support additional default labels to be added to the front. + * TODO: Look at other utilities for future refactoring. (This may not be needed.) + */ + public static AttributeDefinition formLabelAttributeDefinition( + AttributeDefinition oldAttributeDefinition, Table table, List<String> additionalLabels) + throws ColumnNotFoundException { + Collection<String> originalLabelColumnNames = + Arrays.asList(TableUtilities.getValidStringColumnNamesInTable(table)); + Collection<String> newLabelColumnNames = new ArrayList<String>(); + newLabelColumnNames.addAll(additionalLabels); + newLabelColumnNames.addAll(originalLabelColumnNames); + + AttributeDefinition labelAttributeDefinition = cloneToDropdownAttributeDefinition( + oldAttributeDefinition, newLabelColumnNames, newLabelColumnNames); + + return labelAttributeDefinition; + } + public static AttributeDefinition formDateAttributeDefinition( AttributeDefinition oldAttributeDefinition, Table table) throws ColumnNotFoundException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-06 16:59:04
|
Revision: 1122 http://cishell.svn.sourceforge.net/cishell/?rev=1122&view=rev Author: pataphil Date: 2010-08-06 16:58:57 +0000 (Fri, 06 Aug 2010) Log Message: ----------- * Java 1.5'ified CollectionUtilities. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java 2010-08-05 19:51:42 UTC (rev 1121) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/CollectionUtilities.java 2010-08-06 16:58:57 UTC (rev 1122) @@ -10,13 +10,13 @@ /* Return only elements of the Collection which are mapped to true in the * Dictionary */ - public static Collection grabSelectedValues( - Collection elements, Dictionary selectionDictionary) { - Collection selectedElements = new ArrayList(); + public static<K, V> Collection<K> grabSelectedValues( + Collection<K> elements, Dictionary<K, V> selectionDictionary) { + Collection<K> selectedElements = new ArrayList<K>(); - for (Iterator elementsIt = elements.iterator(); elementsIt.hasNext();) { - String element = (String) elementsIt.next(); - Object isSelected = selectionDictionary.get(element); + for (Iterator<K> elementsIt = elements.iterator(); elementsIt.hasNext();) { + K element = elementsIt.next(); + V isSelected = selectionDictionary.get(element); if ((isSelected != null) && (isSelected instanceof Boolean)) { if (((Boolean) isSelected).booleanValue()) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:51:48
|
Revision: 1121 http://cishell.svn.sourceforge.net/cishell/?rev=1121&view=rev Author: pataphil Date: 2010-08-05 19:51:42 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Added org.cishell.utility.datastructure to the build. Modified Paths: -------------- trunk/deployment/org.cishell.reference.database.feature/feature.xml trunk/deployment/org.cishell.reference.feature/feature.xml trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml Modified: trunk/deployment/org.cishell.reference.database.feature/feature.xml =================================================================== --- trunk/deployment/org.cishell.reference.database.feature/feature.xml 2010-08-05 19:47:55 UTC (rev 1120) +++ trunk/deployment/org.cishell.reference.database.feature/feature.xml 2010-08-05 19:51:42 UTC (rev 1121) @@ -96,6 +96,13 @@ unpack="false"/> <plugin + id="org.cishell.utility.datastructure" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin id="google_collections" download-size="0" install-size="0" Modified: trunk/deployment/org.cishell.reference.feature/feature.xml =================================================================== --- trunk/deployment/org.cishell.reference.feature/feature.xml 2010-08-05 19:47:55 UTC (rev 1120) +++ trunk/deployment/org.cishell.reference.feature/feature.xml 2010-08-05 19:51:42 UTC (rev 1121) @@ -122,6 +122,13 @@ unpack="false"/> <plugin + id="org.cishell.utility.datastructure" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin id="org.cishell.algorithm.convertergraph" download-size="0" install-size="0" Modified: trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml =================================================================== --- trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2010-08-05 19:47:55 UTC (rev 1120) +++ trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2010-08-05 19:51:42 UTC (rev 1121) @@ -212,6 +212,12 @@ <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.utility.datastructure"/> + <param name="project.name" value="/core/org.cishell.utility.datastructure"/> + <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="google-collections"/> <param name="project.name" value="/libs/google-collections"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:48:01
|
Revision: 1120 http://cishell.svn.sourceforge.net/cishell/?rev=1120&view=rev Author: pataphil Date: 2010-08-05 19:47:55 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Changed org.cishell.utilities.datastructure to org.cishell.utility.datastructure. Modified Paths: -------------- trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/GUIBuilderUtilities.java Modified: trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF 2010-08-05 19:47:42 UTC (rev 1119) +++ trunk/core/org.cishell.utility.swt/META-INF/MANIFEST.MF 2010-08-05 19:47:55 UTC (rev 1120) @@ -8,7 +8,7 @@ org.eclipse.core.runtime Import-Package: com.google.common.collect, org.cishell.utilities, - org.cishell.utilities.datastructure + org.cishell.utility.datastructure Export-Package: org.cishell.utility.swt, org.cishell.utility.swt.model, org.cishell.utility.swt.model.datasynchronizer Modified: trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/GUIBuilderUtilities.java =================================================================== --- trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/GUIBuilderUtilities.java 2010-08-05 19:47:42 UTC (rev 1119) +++ trunk/core/org.cishell.utility.swt/src/org/cishell/utility/swt/GUIBuilderUtilities.java 2010-08-05 19:47:55 UTC (rev 1120) @@ -1,6 +1,6 @@ package org.cishell.utility.swt; -import org.cishell.utilities.datastructure.ObjectContainer; +import org.cishell.utility.datastructure.ObjectContainer; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ShellEvent; import org.eclipse.swt.events.ShellListener; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:47:49
|
Revision: 1119 http://cishell.svn.sourceforge.net/cishell/?rev=1119&view=rev Author: pataphil Date: 2010-08-05 19:47:42 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Misc. cleanup. 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/AlgorithmWrapper.java trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.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 2010-08-05 19:44:46 UTC (rev 1118) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2010-08-05 19:47:42 UTC (rev 1119) @@ -24,8 +24,8 @@ import org.cishell.app.service.datamanager.DataManagerListener; import org.cishell.app.service.datamanager.DataManagerService; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.workspace.CIShellApplication; @@ -69,13 +69,11 @@ import org.osgi.service.log.LogService; public abstract class AbstractDataManagerView - extends ViewPart - implements DataManagerListener, BundleListener { + extends ViewPart implements BundleListener, DataManagerListener { private String brandPluginID; private DataManagerService manager; private TreeViewer viewer; private TreeEditor editor; - // TODO: Finish cleaning this file up. private Text newEditor; private DataGUIItem rootItem; /* @@ -85,7 +83,7 @@ private boolean updatingTreeItem; private Tree tree; private Menu menu; - private Map dataToDataGUIItemMap; + private Map<Data, DataGUIItem> dataToDataGUIItemMap; private AlgorithmFactory saveFactory; private AlgorithmFactory viewFactory; private AlgorithmFactory viewWithFactory; @@ -93,18 +91,17 @@ private SaveListener saveListener; private ViewListener viewListener; private ViewWithListener viewWithListener; - private LogService log; + private LogService logger; public AbstractDataManagerView(String brandPluginID) { this.brandPluginID = brandPluginID; - dataToDataGUIItemMap = new HashMap(); + this.dataToDataGUIItemMap = new HashMap<Data, DataGUIItem>(); + this.manager = Activator.getDataManagerService(); + this.logger = Activator.getLogService(); - manager = Activator.getDataManagerService(); - log = Activator.getLogService(); - - if (manager == null) { - if (log != null) { - log.log(LogService.LOG_ERROR, "Data Manager Service unavailable!"); + if (this.manager == null) { + if (this.logger != null) { + this.logger.log(LogService.LOG_ERROR, "Data Manager Service unavailable!"); } } } @@ -122,41 +119,39 @@ * @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"); this.viewer = new TreeViewer(parent); this.viewer.setContentProvider(new DataTreeContentProvider()); this.viewer.setLabelProvider(new DataTreeLabelProvider()); - rootItem = new DataGUIItem(null, null, this.brandPluginID); - this.viewer.setInput(rootItem); + this.rootItem = new DataGUIItem(null, null, this.brandPluginID); + this.viewer.setInput(this.rootItem); this.viewer.expandAll(); - // grab the tree and add the appropriate listeners - tree = this.viewer.getTree(); - tree.addSelectionListener(new DatamodelSelectionListener()); - tree.addMouseListener(new ContextMenuListener()); + // Grab the tree and add the appropriate listeners. + this.tree = this.viewer.getTree(); + this.tree.addSelectionListener(new DatamodelSelectionListener()); + this.tree.addMouseListener(new ContextMenuListener()); - // setup the context menu for the tree - menu = new Menu(tree); - menu.setVisible(false); + // Setup the context menu for the tree. + this.menu = new Menu(tree); + this.menu.setVisible(false); - MenuItem saveItem = new MenuItem(menu, SWT.PUSH); + MenuItem saveItem = new MenuItem(this.menu, SWT.PUSH); saveItem.setText("Save"); - saveListener = new SaveListener(); - saveItem.addListener(SWT.Selection, saveListener); + this.saveListener = new SaveListener(); + saveItem.addListener(SWT.Selection, this.saveListener); - MenuItem viewItem = new MenuItem(menu, SWT.PUSH); + MenuItem viewItem = new MenuItem(this.menu, SWT.PUSH); viewItem.setText("View"); - viewListener = new ViewListener(); - viewItem.addListener(SWT.Selection, viewListener); + this.viewListener = new ViewListener(); + viewItem.addListener(SWT.Selection, this.viewListener); - MenuItem viewWithItem = new MenuItem(menu, SWT.PUSH); + MenuItem viewWithItem = new MenuItem(this.menu, SWT.PUSH); viewWithItem.setText("View With..."); - viewWithListener = new ViewWithListener(); - viewWithItem.addListener(SWT.Selection, viewWithListener); + this.viewWithListener = new ViewWithListener(); + viewWithItem.addListener(SWT.Selection, this.viewWithListener); - MenuItem renameItem = new MenuItem(menu, SWT.PUSH); + MenuItem renameItem = new MenuItem(this.menu, SWT.PUSH); renameItem.setText("Rename"); renameItem.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { @@ -164,19 +159,19 @@ } }); - MenuItem discardItem = new MenuItem(menu, SWT.PUSH); + MenuItem discardItem = new MenuItem(this.menu, SWT.PUSH); discardItem.setText("Discard"); - discardListener = new DiscardListener(); - discardItem.addListener(SWT.Selection, discardListener); - tree.setMenu(menu); + this.discardListener = new DiscardListener(); + discardItem.addListener(SWT.Selection, this.discardListener); + this.tree.setMenu(this.menu); // Allow cells to be edited on double click or when pressing enter on them. - this.editor = new TreeEditor(tree); + this.editor = new TreeEditor(this.tree); this.editor.horizontalAlignment = SWT.LEFT; this.editor.grabHorizontal = true; this.editor.minimumWidth = 50; - // listen to OSGi for models being added by plugins + // Listen to OSGi for models being added by plugins. if (this.manager != null) { this.manager.addDataManagerListener(this); } else { @@ -210,23 +205,22 @@ public void dataAdded(final Data newData, String label) { - //get the new data's parent GUI Item (either root or another data item) + // Get the new data's parent GUI Item (either root or another data item). DataGUIItem parentItem = getParent(newData); - // wrap the new data in a DataGUIItem - final DataGUIItem newItem = new DataGUIItem(newData, parentItem, - this.brandPluginID); + // Wrap the new data in a DataGUIItem. + final DataGUIItem newItem = new DataGUIItem(newData, parentItem, this.brandPluginID); - // notify the parent DataModelGUIItem of its new child + // Notify the parent DataModelGUIItem of its new child. parentItem.addChild(newItem); - // keep a reference to the new model in the model->TreeItem mapping so - // that - // it can be used in the future if it has a child - dataToDataGUIItemMap.put(newData, newItem); + /* Keep a reference to the new model in the model->TreeItem mapping so that it can be used + * in the future if it has a child. + */ + this.dataToDataGUIItemMap.put(newData, newItem); // update the ModelManager with the new selection - final Set selection = new HashSet(); + final Set<Data> selection = new HashSet<Data>(); selection.add(newData); guiRun(new Runnable() { @@ -246,20 +240,21 @@ } private DataGUIItem getParent(Data data) { - Dictionary modelDictionary = data.getMetadata(); + Dictionary<String, Object> modelDictionary = data.getMetadata(); Data parent = (Data) modelDictionary.get(DataProperty.PARENT); DataGUIItem parentItem; + if (parent == null) { - // if it has no parent, it is a child of the root - parentItem = rootItem; + // If it has no parent, it is a child of the root. + parentItem = this.rootItem; } else { - // otherwise find the associated DataModelGUIItem for the parent - parentItem = (DataGUIItem) dataToDataGUIItemMap.get(parent); + // Otherwise find the associated DataModelGUIItem for the parent. + parentItem = this.dataToDataGUIItemMap.get(parent); - //The parent may not be in the GUI. If its not, then use root item + // The parent may not be in the GUI. If its not, then use root item. if (parentItem == null) { - parentItem = rootItem; + parentItem = this.rootItem; } } @@ -276,7 +271,7 @@ public void dataLabelChanged(Data data, String label) { if (data != null && label != null) { - TreeItem[] treeItems = tree.getItems(); + TreeItem[] treeItems = this.tree.getItems(); for (int i = 0; i < treeItems.length; ++i) { if (((DataGUIItem)treeItems[i].getData()).getModel() == data) { updateText(label, treeItems[i]); @@ -287,20 +282,21 @@ } public void dataRemoved(Data data) { - TreeItem[] treeItems = tree.getItems(); + TreeItem[] treeItems = this.tree.getItems(); for (int i = 0; i < treeItems.length; ++i) { if (((DataGUIItem)treeItems[i].getData()).getModel() == data) { - tree.clear(tree.indexOf(treeItems[i]), false); + this.tree.clear(this.tree.indexOf(treeItems[i]), false); } } } public void dataSelected(final Data[] data) { if (data != null) { - //setFocus(); guiRun(new Runnable() { public void run() { - Set itemSet = new HashSet(); + // TODO: Abstract this? + Set<TreeItem> itemSet = new HashSet<TreeItem>(); + for (int i = 0; i < data.length; ++i) { TreeItem[] treeItems = tree.getItems(); for (int j = 0; j < treeItems.length; ++j) { @@ -310,34 +306,39 @@ } } } - tree.setSelection((TreeItem[]) itemSet - .toArray(new TreeItem[0])); - getSite().getSelectionProvider().setSelection( - new StructuredSelection(data)); + + tree.setSelection(itemSet.toArray(new TreeItem[0])); + getSite().getSelectionProvider().setSelection(new StructuredSelection(data)); } }); } } /* - * enables/disables save item in the context menu based on whether or not + * Enables/disables save item in the context menu based on whether or not * their is an available Persister for the given model */ private void updateContextMenu(Data model) { - saveFactory = enableMenuItemCheck(saveFactory, - "org.cishell.reference.gui.persistence.save.Save", model, 0); - viewFactory = enableMenuItemCheck(viewFactory, - "org.cishell.reference.gui.persistence.view.FileView", model, 1); - viewWithFactory = enableMenuItemCheck(viewWithFactory, - "org.cishell.reference.gui.persistence.viewwith.FileViewWith", model, 2); +// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException { + this.saveFactory = enableMenuItemCheck( + this.saveFactory, "org.cishell.reference.gui.persistence.save.Save", model, 0); + this.viewFactory = enableMenuItemCheck( + this.viewFactory, "org.cishell.reference.gui.persistence.view.FileView", model, 1); + this.viewWithFactory = enableMenuItemCheck( + this.viewWithFactory, + "org.cishell.reference.gui.persistence.viewwith.FileViewWith", + model, + 2); } private AlgorithmFactory enableMenuItemCheck( - AlgorithmFactory algorithmFactory, String service, Data model, - int menuNdx) { + AlgorithmFactory algorithmFactory, String service, Data model, int menuIndex) { +// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException { boolean validSaveFactory = false; + if (algorithmFactory == null) { algorithmFactory = Activator.getService(service); + if (algorithmFactory != null) { validSaveFactory = true; } @@ -349,13 +350,17 @@ if (validSaveFactory) { Algorithm algorithm = algorithmFactory.createAlgorithm( - new Data[] { model }, new Hashtable(), Activator - .getCIShellContext()); + new Data[] { model }, + new Hashtable<String, Object>(), + Activator.getCIShellContext()); + if (algorithm != null) { enabled = true; } } - menu.getItem(menuNdx).setEnabled(enabled); + + this.menu.getItem(menuIndex).setEnabled(enabled); + return algorithmFactory; } @@ -367,7 +372,7 @@ public void widgetSelected(SelectionEvent e) { Tree tree = (Tree) e.getSource(); TreeItem[] selection = tree.getSelection(); - Set models = new HashSet(); + Set<Data> models = new HashSet<Data>(); Data[] modelArray = new Data[selection.length]; for (int i = 0; i < selection.length; i++) { @@ -396,7 +401,7 @@ // Identify the selected row, only allow input if there is a single // selected row - TreeItem[] selection = tree.getSelection(); + TreeItem[] selection = this.tree.getSelection(); if (selection.length != 1) { return; @@ -409,32 +414,33 @@ } // The control that will be the editor must be a child of the Table - newEditor = new Text(tree, SWT.NONE); - newEditor.setText(item.getText()); - newEditor.addFocusListener(new FocusAdapter() { + this.newEditor = new Text(this.tree, SWT.NONE); + this.newEditor.setText(item.getText()); + this.newEditor.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { if (!updatingTreeItem) { //updateText(newEditor.getText(), item); AbstractDataManagerView.this.manager.setLabel( - ((DataGUIItem)item.getData()).getModel(), newEditor.getText()); + ((DataGUIItem) item.getData()).getModel(), + AbstractDataManagerView.this.newEditor.getText()); // FELIX. This is not > stupidness. } } }); // ENTER ESC - newEditor.addKeyListener(new KeyAdapter() { + this.newEditor.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { - if ((e.character == SWT.CR) && !updatingTreeItem) { - updateText(newEditor.getText(), item); + if ((e.character == SWT.CR) && !AbstractDataManagerView.this.updatingTreeItem) { + updateText(AbstractDataManagerView.this.newEditor.getText(), item); } else if (e.keyCode == SWT.ESC) { - newEditor.dispose(); + AbstractDataManagerView.this.newEditor.dispose(); } } }); - newEditor.selectAll(); - newEditor.setFocus(); - this.editor.setEditor(newEditor, item); + this.newEditor.selectAll(); + this.newEditor.setFocus(); + this.editor.setEditor(this.newEditor, item); } /* @@ -442,7 +448,7 @@ * by the TreeEditor for renaming - only if the new name is valid though */ private void updateText(String newLabel, TreeItem item) { - updatingTreeItem = true; + this.updatingTreeItem = true; if (newLabel.startsWith(">")) newLabel = newLabel.substring(1); @@ -454,7 +460,7 @@ Data model = treeItem.getModel(); model.getMetadata().put(DataProperty.LABEL, newLabel); viewer.refresh(); - newEditor.dispose(); + this.newEditor.dispose(); updatingTreeItem = false; } @@ -466,12 +472,13 @@ private class ContextMenuListener extends MouseAdapter { public void mouseUp(MouseEvent event) { if (event.button == 3) { - TreeItem item = tree.getItem(new Point(event.x, event.y)); + TreeItem item = + AbstractDataManagerView.this.tree.getItem(new Point(event.x, event.y)); if (item != null) { - tree.getMenu().setVisible(true); + AbstractDataManagerView.this.tree.getMenu().setVisible(true); } else { - tree.getMenu().setVisible(false); + AbstractDataManagerView.this.tree.getMenu().setVisible(false); } } } @@ -480,28 +487,26 @@ private class SaveListener implements Listener { public void handleEvent(Event event) { - if (saveFactory != null) { - Data data[] = AbstractDataManagerView.this.manager - .getSelectedData(); - Algorithm algorithm = saveFactory - .createAlgorithm(data, new Hashtable(), Activator - .getCIShellContext()); - try{ + if (AbstractDataManagerView.this.saveFactory != null) { + Data data[] = AbstractDataManagerView.this.manager.getSelectedData(); + Algorithm algorithm = AbstractDataManagerView.this.saveFactory.createAlgorithm( + data, new Hashtable<String, Object>(), Activator.getCIShellContext()); + + try { algorithm.execute(); - }catch (AlgorithmExecutionException aee) { - if (log != null) { - log.log(LogService.LOG_ERROR, - aee.getMessage(), - aee); - aee.printStackTrace(); + } catch (AlgorithmExecutionException e) { + if (AbstractDataManagerView.this.logger != null) { + AbstractDataManagerView.this.logger.log( + LogService.LOG_ERROR, e.getMessage(), e); + e.printStackTrace(); + } else { + AbstractDataManagerView.this.logger = Activator.getLogService(); + AbstractDataManagerView.this.logger.log( + LogService.LOG_ERROR, + "org.cishell.framework.algorithm.AlgorithmExecutionException", + e); + e.printStackTrace(); } - else { - log = Activator.getLogService(); - log.log(LogService.LOG_ERROR, - "org.cishell.framework.algorithm.AlgorithmExecutionException", - aee); - aee.printStackTrace(); - } } } } @@ -509,27 +514,22 @@ private class ViewListener implements Listener { public void handleEvent(Event event) { - if (viewFactory != null) { - Data data[] = AbstractDataManagerView.this.manager - .getSelectedData(); - Algorithm algorithm = viewFactory - .createAlgorithm(data, new Hashtable(), Activator - .getCIShellContext()); + if (AbstractDataManagerView.this.viewFactory != null) { + Data data[] = AbstractDataManagerView.this.manager.getSelectedData(); + Algorithm algorithm = AbstractDataManagerView.this.viewFactory.createAlgorithm( + data, new Hashtable<String, Object>(), Activator.getCIShellContext()); + try { algorithm.execute(); - }catch (AlgorithmExecutionException aee) { - if (log != null) { - log.log(LogService.LOG_ERROR, - aee.getMessage(), - aee); + } catch (AlgorithmExecutionException e) { + if (logger != null) { + logger.log(LogService.LOG_ERROR, e.getMessage(), e); + } else { + logger = Activator.getLogService(); + logger.log(LogService.LOG_ERROR, e.getMessage(), e); } - else { - log = Activator.getLogService(); - log.log(LogService.LOG_ERROR, - aee.getMessage(), - aee); - } - aee.printStackTrace(); + + e.printStackTrace(); } } } @@ -539,14 +539,16 @@ public void handleEvent(Event event) { IMenuManager topLevelMenu = CIShellApplication.getMenuManager(); IMenuManager fileMenu = topLevelMenu.findMenuUsingPath("File"); - BundleContext bContext = Activator.getBundleContext(); + BundleContext bundleContext = Activator.getBundleContext(); try { - ServiceReference[] ref = bContext.getAllServiceReferences(AlgorithmFactory.class.getName(), - "(service.pid=org.cishell.reference.gui.persistence.viewwith.FileViewWith)"); + ServiceReference[] serviceReference = bundleContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), + "(service.pid=org.cishell.reference.gui.persistence.viewwith.FileViewWith)"); - if (ref != null && ref.length > 0) { - ActionContributionItem action = (ActionContributionItem)fileMenu.find(getItemID(ref[0])); + if ((serviceReference != null) && (serviceReference.length > 0)) { + ActionContributionItem action = + (ActionContributionItem) fileMenu.find(getItemID(serviceReference[0])); action.getAction().run(); } } catch (InvalidSyntaxException e) { @@ -557,18 +559,19 @@ private class DiscardListener implements Listener { public void handleEvent(Event event) { - TreeItem[] selection = AbstractDataManagerView.this.tree - .getSelection(); + TreeItem[] selections = AbstractDataManagerView.this.tree.getSelection(); - for (int i = 0; i < selection.length; i++) { - DataGUIItem item = (DataGUIItem) selection[i].getData(); + for (TreeItem selection : selections) { +// for (int i = 0; i < selections.length; i++) { +// DataGUIItem item = (DataGUIItem) selections[i].getData(); + DataGUIItem item = (DataGUIItem) selection.getData(); DataGUIItem parent = item.getParent(); if (parent != null) { parent.removeChild(item); } - dataToDataGUIItemMap.remove(item.getModel()); + AbstractDataManagerView.this.dataToDataGUIItemMap.remove(item.getModel()); AbstractDataManagerView.this.manager.removeData(item.getModel()); } @@ -579,13 +582,11 @@ private class DataModelSelectionProvider implements ISelectionProvider { - - private Set listeners = new HashSet(); - + private Set<ISelectionChangedListener> listeners = + new HashSet<ISelectionChangedListener>(); private ISelection selection; - public void addSelectionChangedListener( - ISelectionChangedListener listener) { + public void addSelectionChangedListener(ISelectionChangedListener listener) { listeners.add(listener); } @@ -593,17 +594,19 @@ return selection; } - public void removeSelectionChangedListener( - ISelectionChangedListener listener) { + public void removeSelectionChangedListener(ISelectionChangedListener listener) { listeners.remove(listener); } private TreeItem getTreeItem(Data model, TreeItem[] items) { TreeItem result = null; int i = 0; - while (i < items.length && result == null) { + + while ((i < items.length) && (result == null)) { DataGUIItem data = ((DataGUIItem) items[i].getData()); - if (data != null) { // not sure why this happens.. + + // TODO: Not sure why this happens... + if (data != null) { Data item = data.getModel(); if (item == model) @@ -628,37 +631,37 @@ this.selection = selection; AbstractDataManagerView.this.viewer.refresh(true); - if (selection != null - && selection instanceof IStructuredSelection) { - IStructuredSelection ss = (IStructuredSelection) selection; - Iterator iterator = ss.iterator(); - TreeItem[] newTreeSelection = new TreeItem[ss.size()]; + if ((selection != null) && (selection instanceof IStructuredSelection)) { + IStructuredSelection selections = (IStructuredSelection) selection; + Iterator<?> iterator = selections.iterator(); + TreeItem[] newTreeSelection = new TreeItem[selections.size()]; int i = 0; + while (iterator.hasNext()) { Object next = iterator.next(); + if (next instanceof Data) { - TreeItem result = getTreeItem((Data) next, tree - .getItems()); + TreeItem result = getTreeItem( + (Data) next, AbstractDataManagerView.this.tree.getItems()); newTreeSelection[i] = result; AbstractDataManagerView.this.viewer.expandToLevel( - dataToDataGUIItemMap.get(next), 0); + AbstractDataManagerView.this.dataToDataGUIItemMap.get(next), 0); } + i++; } - tree.setSelection(newTreeSelection); + AbstractDataManagerView.this.tree.setSelection(newTreeSelection); } - Iterator listenerIterator = listeners.iterator(); + Iterator<ISelectionChangedListener> listenerIterator = listeners.iterator(); + while (listenerIterator.hasNext()) { - ISelectionChangedListener listener = (ISelectionChangedListener) listenerIterator - .next(); - SelectionChangedEvent event = new SelectionChangedEvent( - this, selection); + ISelectionChangedListener listener = listenerIterator.next(); + SelectionChangedEvent event = new SelectionChangedEvent(this, selection); listener.selectionChanged(event); } } } - } } 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 2010-08-05 19:44:46 UTC (rev 1118) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmAction.java 2010-08-05 19:47:42 UTC (rev 1119) @@ -33,29 +33,38 @@ public class AlgorithmAction extends Action implements AlgorithmProperty, DataManagerListener { - protected CIShellContext ciContext; - protected BundleContext bContext; - protected ServiceReference ref; + protected CIShellContext ciShellContext; + protected BundleContext bundleContext; + protected ServiceReference serviceReference; protected Data[] data; protected Data[] originalData; protected Converter[][] converters; public AlgorithmAction( - ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { - this((String)ref.getProperty(LABEL), ref, bContext, ciContext); + ServiceReference serviceReference, + BundleContext bundleContext, + CIShellContext ciShellContext) { + this( + (String) serviceReference.getProperty(LABEL), + serviceReference, + bundleContext, + ciShellContext); } public AlgorithmAction( - String label, ServiceReference ref, BundleContext bContext, CIShellContext ciContext) { - this.ref = ref; - this.ciContext = ciContext; - this.bContext = bContext; + String label, + ServiceReference serviceReference, + BundleContext bundleContext, + CIShellContext ciShellContext) { + this.serviceReference = serviceReference; + this.ciShellContext = ciShellContext; + this.bundleContext = bundleContext; setText(label); - setToolTipText((String)ref.getProperty(AlgorithmProperty.DESCRIPTION)); + setToolTipText((String)serviceReference.getProperty(AlgorithmProperty.DESCRIPTION)); DataManagerService dataManager = (DataManagerService) - bContext.getService(bContext.getServiceReference( + bundleContext.getService(bundleContext.getServiceReference( DataManagerService.class.getName())); dataManager.addDataManagerListener(this); @@ -64,12 +73,18 @@ public void run() { try { - printAlgorithmInformation(ref, ciContext); - - Algorithm algorithm = new AlgorithmWrapper(ref, bContext, ciContext, originalData, data, converters); + printAlgorithmInformation(this.serviceReference, this.ciShellContext); + + Algorithm algorithm = new AlgorithmWrapper( + this.serviceReference, + this.bundleContext, + this.ciShellContext, + this.originalData, + this.data, + this.converters); SchedulerService scheduler = (SchedulerService) getService(SchedulerService.class); - scheduler.schedule(algorithm, ref); + scheduler.schedule(algorithm, this.serviceReference); } catch (Throwable exception) { // Just in case an uncaught exception occurs. Eclipse will swallow errors thrown here. exception.printStackTrace(); @@ -134,76 +149,77 @@ return inData; } - + public void dataSelected(Data[] selectedData) { - String inDataString = (String)ref.getProperty(IN_DATA); + String inDataString = (String) this.serviceReference.getProperty(IN_DATA); String[] inData = separateInData(inDataString); - if ((inData.length == 1 && inData[0].equalsIgnoreCase(NULL_DATA))) { - data = new Data[0]; + if ((inData.length == 1) && inData[0].equalsIgnoreCase(NULL_DATA)) { + this.data = new Data[0]; } else if (selectedData == null) { - data = null; + this.data = null; } else { - DataConversionService converter = (DataConversionService) - ciContext.getService(DataConversionService.class.getName()); + DataConversionService converter = + (DataConversionService) this.ciShellContext.getService( + DataConversionService.class.getName()); - List dataSet = new ArrayList(Arrays.asList(selectedData)); - data = new Data[inData.length]; - converters = new Converter[inData.length][]; + List<Data> dataSet = new ArrayList<Data>(Arrays.asList(selectedData)); + this.data = new Data[inData.length]; + this.converters = new Converter[inData.length][]; - for (int i=0; i < inData.length; i++) { - for (int j=0; j < dataSet.size(); j++) { - Data datum = (Data) dataSet.get(j); + for (int ii = 0; ii < inData.length; ii++) { + for (int jj = 0; jj < dataSet.size(); jj++) { + Data datum = (Data) dataSet.get(jj); if (datum != null) { - if (isAssignableFrom(inData[i], datum)) { - dataSet.remove(j); - data[i] = datum; - converters[i] = null; + if (isAssignableFrom(inData[ii], datum)) { + dataSet.remove(jj); + this.data[ii] = datum; + this.converters[ii] = null; } else { - Converter[] conversion = converter.findConverters(datum, inData[i]); + Converter[] conversion = converter.findConverters(datum, inData[ii]); if (conversion.length > 0) { - dataSet.remove(j); - data[i] = datum; - converters[i] = conversion; + dataSet.remove(jj); + this.data[ii] = datum; + this.converters[ii] = conversion; } } } } - //if there isn't a converter for one of the inputs - //then this data isn't useful - if (data[i] == null) { - data = null; + // If there isn't a converter for one of the inputs then this data isn't useful. + if (this.data[ii] == null) { + this.data = null; + break; } } } - if (data != null) { - originalData = (Data[]) data.clone(); + if (this.data != null) { + this.originalData = (Data[]) this.data.clone(); } else { - originalData = null; + this.originalData = null; } - setEnabled(data != null); + setEnabled(this.data != null); } private boolean isAssignableFrom(String type, Data datum) { Object data = datum.getData(); boolean assignable = false; - if (type != null && type.equalsIgnoreCase(datum.getFormat())) { + if ((type != null) && type.equalsIgnoreCase(datum.getFormat())) { assignable = true; } else if (data != null) { try { - Class c = Class.forName(type, false, data.getClass().getClassLoader()); + Class<?> clazz = Class.forName(type, false, data.getClass().getClassLoader()); - if (c != null && c.isInstance(data)) { + if (clazz != null && clazz.isInstance(data)) { assignable = true; } - } catch (ClassNotFoundException e) { /*ignore*/ } + } catch (ClassNotFoundException e) { /* Ignore. */ } } return assignable; @@ -213,16 +229,17 @@ public void dataLabelChanged(Data data, String label) {} public void dataRemoved(Data data) {} - private Object getService(Class clas) { - ServiceReference ref = bContext.getServiceReference(clas.getName()); - if (ref != null) { - return bContext.getService(ref); + private Object getService(Class<?> clazz) { + ServiceReference serviceReference = bundleContext.getServiceReference(clazz.getName()); + + if (serviceReference != null) { + return bundleContext.getService(serviceReference); } return null; } public ServiceReference getServiceReference(){ - return ref; + return this.serviceReference; } } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-05 19:44:46 UTC (rev 1118) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/AlgorithmWrapper.java 2010-08-05 19:47:42 UTC (rev 1119) @@ -52,26 +52,26 @@ import org.osgi.service.metatype.MetaTypeService; import org.osgi.service.metatype.ObjectClassDefinition; -public class AlgorithmWrapper - implements Algorithm, AlgorithmProperty, ProgressTrackable { - protected ServiceReference ref; - protected BundleContext bContext; - protected CIShellContext ciContext; +public class AlgorithmWrapper implements Algorithm, AlgorithmProperty, ProgressTrackable { + protected ServiceReference serviceReference; + protected BundleContext bundleContext; + protected CIShellContext ciShellContext; protected Data[] originalData; protected Data[] data; protected Converter[][] converters; protected ProgressMonitor progressMonitor; protected Algorithm algorithm; - public AlgorithmWrapper(ServiceReference ref, - BundleContext bContext, - CIShellContext ciContext, - Data[] originalData, - Data[] data, - Converter[][] converters) { - this.ref = ref; - this.bContext = bContext; - this.ciContext = ciContext; + public AlgorithmWrapper( + ServiceReference serviceReference, + BundleContext bundleContext, + CIShellContext ciShellContext, + Data[] originalData, + Data[] data, + Converter[][] converters) { + this.serviceReference = serviceReference; + this.bundleContext = bundleContext; + this.ciShellContext = ciShellContext; this.originalData = originalData; this.data = data; this.converters = converters; @@ -83,45 +83,45 @@ */ public Data[] execute() { try { - AlgorithmFactory factory = getAlgorithmFactory(bContext, ref); - + AlgorithmFactory factory = getAlgorithmFactory(bundleContext, serviceReference); + if (factory == null) { return null; } - - String pid = (String)ref.getProperty(Constants.SERVICE_PID); + String pid = (String) serviceReference.getProperty(Constants.SERVICE_PID); + // Convert input data to the correct format. - boolean conversionSuccessful = - tryConvertingDataToRequiredFormat(data, converters); - + boolean conversionSuccessful = tryConvertingDataToRequiredFormat(data, converters); + if (!conversionSuccessful) { return null; } boolean inputIsValid = testDataValidityIfPossible(factory, data); - if (!inputIsValid) + if (!inputIsValid) { return null; + } // Create algorithm parameters. - String metatype_pid = getMetaTypeID(ref); + String metatypePID = getMetaTypeID(serviceReference); MetaTypeProvider provider = - getPossiblyMutatedMetaTypeProvider(metatype_pid, pid, factory); + getPossiblyMutatedMetaTypeProvider(metatypePID, pid, factory); - Dictionary parameters = - getUserEnteredParameters(metatype_pid, provider); + Dictionary<String, Object> parameters = + getUserEnteredParameters(metatypePID, provider); // Check to see if the user cancelled the operation. if (parameters == null) { return null; } - printParameters(metatype_pid, provider, parameters); + printParameters(metatypePID, provider, parameters); // Create the algorithm. - algorithm = createAlgorithm(factory, data, parameters, ciContext); + algorithm = createAlgorithm(factory, data, parameters, ciShellContext); if (algorithm == null) { return null; @@ -143,11 +143,11 @@ return outData; } catch (Exception e) { - GUIBuilderService builder = (GUIBuilderService)ciContext.getService + GUIBuilderService builder = (GUIBuilderService)ciShellContext.getService (GUIBuilderService.class.getName()); String errorMessage = "An error occurred while preparing to run " - + "the algorithm \"" + ref.getProperty(AlgorithmProperty.LABEL) + + "the algorithm \"" + serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\""; builder.showError("Error!", errorMessage, e); @@ -157,50 +157,56 @@ return null; } - protected AlgorithmFactory getAlgorithmFactory(BundleContext bContext, - ServiceReference ref) { + protected AlgorithmFactory getAlgorithmFactory( + BundleContext bundleContext, ServiceReference serviceReference) { AlgorithmFactory algorithmFactory = - (AlgorithmFactory) bContext.getService(ref); + (AlgorithmFactory) bundleContext.getService(serviceReference); + if (algorithmFactory == null) { String errorMessage = "Could not create AlgorithmFactory for the algorithm " - + "\"" + ref.getProperty(AlgorithmProperty.LABEL) + "\"."; + + "\"" + serviceReference.getProperty(AlgorithmProperty.LABEL) + "\"."; String details = "The algorithm's pid was \"" - + ref.getProperty(Constants.SERVICE_PID) + + serviceReference.getProperty(Constants.SERVICE_PID) + "\" (potentially useful for debugging purposes)."; - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); + GUIBuilderService builder = + (GUIBuilderService) ciShellContext.getService(GUIBuilderService.class.getName()); builder.showError("Error!", errorMessage, details); - log(LogService.LOG_ERROR, errorMessage); + this.logger(LogService.LOG_ERROR, errorMessage); } return algorithmFactory; } - protected Algorithm createAlgorithm(AlgorithmFactory factory, - Data[] data, - Dictionary parameters, - CIShellContext ciContext) { + protected Algorithm createAlgorithm( + AlgorithmFactory factory, + Data[] data, + Dictionary<String, Object> parameters, + CIShellContext ciContext) { + // TODO: Call on algorithm invocation service here. try { return factory.createAlgorithm(data, parameters, ciContext); } catch (Exception e) { String errorMessage = - "Unexpected error occurred while creating algorithm " + " \"" - + ref.getProperty(AlgorithmProperty.LABEL) + ".\""; - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); + "Unexpected error occurred while creating algorithm " + " \"" + + serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\""; + GUIBuilderService builder = + (GUIBuilderService) ciContext.getService(GUIBuilderService.class.getName()); + // TODO: This is where uncaught exceptions are displayed. builder.showError("Error!", errorMessage, e); log(LogService.LOG_ERROR, errorMessage, e); + return null; } } protected Data[] removeNullData(Data[] outData) { if (outData != null) { - List goodData = new ArrayList(); - for (int i = 0; i < outData.length; i++) { - if (outData[i] != null) { - goodData.add(outData[i]); + List<Data> goodData = new ArrayList<Data>(); + + for (Data data : outData) { + if (data != null) { + goodData.add(data); } } @@ -213,8 +219,8 @@ protected void addDataToDataManager(Data[] outData) { if (outData != null) { DataManagerService dataManager = (DataManagerService) - bContext.getService( - bContext.getServiceReference( + bundleContext.getService( + bundleContext.getServiceReference( DataManagerService.class.getName())); if (outData.length != 0) { @@ -234,15 +240,15 @@ outData = algorithm.execute(); } catch (AlgorithmExecutionException e) { log(LogService.LOG_ERROR, "The Algorithm: \"" - + ref.getProperty(AlgorithmProperty.LABEL) + + serviceReference.getProperty(AlgorithmProperty.LABEL) + "\" had an error while executing: " + e.getMessage(), e); } catch (RuntimeException e) { GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); + ciShellContext.getService(GUIBuilderService.class.getName()); builder.showError("Error!", "An unexpected exception occurred while " + "executing \"" - + ref.getProperty(AlgorithmProperty.LABEL) + ".\"", e); + + serviceReference.getProperty(AlgorithmProperty.LABEL) + ".\"", e); } return outData; @@ -262,7 +268,7 @@ } if (data[i] == null && i < (data.length - 1)) { - log(LogService.LOG_ERROR, "The converter: " + logger(LogService.LOG_ERROR, "The converter: " + converters[i].getClass().getName() + " returned a null result where data was " + "expected when converting the data to give " @@ -282,12 +288,12 @@ String validation = ((DataValidator) factory).validate(data); if (validation != null && validation.length() > 0) { - String label = (String) ref.getProperty(LABEL); + String label = (String) serviceReference.getProperty(LABEL); if (label == null) { label = "Algorithm"; } - log(LogService.LOG_ERROR, + logger(LogService.LOG_ERROR, "INVALID DATA: The data given to \"" + label + "\" is incompatible for this reason: " + validation); return false; @@ -314,7 +320,7 @@ MetaTypeService metaTypeService = (MetaTypeService) Activator.getService(MetaTypeService.class.getName()); if (metaTypeService != null) { - provider = metaTypeService.getMetaTypeInformation(ref.getBundle()); + provider = metaTypeService.getMetaTypeInformation(serviceReference.getBundle()); } if (factory instanceof ParameterMutator && provider != null) { @@ -333,7 +339,7 @@ } if (provider != null) { - provider = wrapProvider(ref, provider); + provider = wrapProvider(serviceReference, provider); } return provider; @@ -345,14 +351,16 @@ } } - protected Dictionary getUserEnteredParameters(String metatype_pid, - MetaTypeProvider provider) { - Dictionary parameters = new Hashtable(); + protected Dictionary<String, Object> getUserEnteredParameters( + String metatypePID, MetaTypeProvider provider) { + Dictionary<String, Object> parameters = new Hashtable<String, Object>(); + if (provider != null) { - GUIBuilderService builder = (GUIBuilderService) - ciContext.getService(GUIBuilderService.class.getName()); + GUIBuilderService builder = + (GUIBuilderService) ciShellContext.getService(GUIBuilderService.class.getName()); - parameters = builder.createGUIandWait(metatype_pid, provider); + // TODO: Make builder.createGUIAndWait return a Dictionary<String, Object>. + parameters = builder.createGUIandWait(metatypePID, provider); } return parameters; @@ -399,9 +407,9 @@ UserPrefsProperty.PUBLISH_PARAM_DEFAULT_PREFS_VALUE); } - protected void log(int logLevel, String message) { + protected void logger(int logLevel, String message) { LogService log = - (LogService) ciContext.getService(LogService.class.getName()); + (LogService) ciShellContext.getService(LogService.class.getName()); if (log != null) { log.log(logLevel, message); } else { @@ -411,7 +419,7 @@ protected void log(int logLevel, String message, Throwable exception) { LogService log = - (LogService) ciContext.getService(LogService.class.getName()); + (LogService) ciShellContext.getService(LogService.class.getName()); if (log != null) { log.log(logLevel, message, exception); } else { @@ -496,7 +504,7 @@ } // Check and act on parentage settings - String parentage = (String) ref.getProperty("parentage"); + String parentage = (String) serviceReference.getProperty("parentage"); if (parentage != null) { parentage = parentage.trim(); if (parentage.equalsIgnoreCase("default")) { @@ -519,12 +527,12 @@ private LogService getLogService() { ServiceReference serviceReference = - bContext.getServiceReference(DataManagerService.class.getName()); + bundleContext.getServiceReference(DataManagerService.class.getName()); LogService log = null; if (serviceReference != null) { - log = (LogService) bContext.getService( - bContext.getServiceReference(LogService.class.getName())); + log = (LogService) bundleContext.getService( + bundleContext.getServiceReference(LogService.class.getName())); } return log; @@ -532,12 +540,12 @@ private ConfigurationAdmin getConfigurationAdmin() { ServiceReference serviceReference = - bContext.getServiceReference(ConfigurationAdmin.class.getName()); + bundleContext.getServiceReference(ConfigurationAdmin.class.getName()); ConfigurationAdmin ca = null; if (serviceReference != null) { - ca = (ConfigurationAdmin) bContext.getService( - bContext.getServiceReference( + ca = (ConfigurationAdmin) bundleContext.getService( + bundleContext.getServiceReference( ConfigurationAdmin.class.getName())); } @@ -545,7 +553,7 @@ } private void logNullOCDWarning(String pid, String metatype_pid) { - this.log(LogService.LOG_WARNING, + this.logger(LogService.LOG_WARNING, "Warning: could not get object class definition '" + metatype_pid + "' from the algorithm '" + pid + "'"); } 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 2010-08-05 19:44:46 UTC (rev 1118) +++ trunk/clients/gui/org.cishell.reference.gui.menumanager/src/org/cishell/reference/gui/menumanager/menu/MenuAdapter.java 2010-08-05 19:47:42 UTC (rev 1119) @@ -89,7 +89,7 @@ /* * 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. + * and a serviceReference while in pidsToServiceReferences that pid has been removed. */ private Map pidsToServiceReferencesCopy; private Document documentObjectModel; @@ -462,7 +462,7 @@ } } - private void initializeMenu() throws InvalidSyntaxException{ + private void initializeMenu() throws InvalidSyntaxException { ServiceReference[] serviceReferences = this.bundleContext.getAllServiceReferences( AlgorithmFactory.class.getName(), null); @@ -493,7 +493,7 @@ } private void makeMenuItem(ServiceReference serviceReference) { - String path = (String)serviceReference.getProperty(MENU_PATH); + String path = (String) serviceReference.getProperty(MENU_PATH); String[] items = null; if (path != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:44:52
|
Revision: 1118 http://cishell.svn.sourceforge.net/cishell/?rev=1118&view=rev Author: pataphil Date: 2010-08-05 19:44:46 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Changed org.cishell.utilities.datastructure to org.cishell.utility.datastructure. Added Paths: ----------- trunk/core/org.cishell.utility.datastructure/ Removed Paths: ------------- trunk/core/org.cishell.utilities.datastructure/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:44:14
|
Revision: 1117 http://cishell.svn.sourceforge.net/cishell/?rev=1117&view=rev Author: pataphil Date: 2010-08-05 19:44:07 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Changed org.cishell.utilities.datastructure to org.cishell.utility.datastructure. Modified Paths: -------------- trunk/core/org.cishell.utilities.datastructure/.project trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utility/datastructure/ObjectContainer.java Added Paths: ----------- trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utility/ trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utility/datastructure/ Removed Paths: ------------- trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/datastructure/ Modified: trunk/core/org.cishell.utilities.datastructure/.project =================================================================== --- trunk/core/org.cishell.utilities.datastructure/.project 2010-08-05 19:23:40 UTC (rev 1116) +++ trunk/core/org.cishell.utilities.datastructure/.project 2010-08-05 19:44:07 UTC (rev 1117) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <projectDescription> - <name>org.cishell.utilities.datastructure</name> + <name>org.cishell.utility.datastructure</name> <comment></comment> <projects> </projects> Modified: trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF 2010-08-05 19:23:40 UTC (rev 1116) +++ trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF 2010-08-05 19:44:07 UTC (rev 1117) @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: CIShell Data Structure Utilities -Bundle-SymbolicName: org.cishell.utilities.datastructure +Bundle-SymbolicName: org.cishell.utility.datastructure Bundle-Version: 1.0.0 Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Export-Package: org.cishell.utilities.datastructure +Export-Package: org.cishell.utility.datastructure Property changes on: trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utility/datastructure ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utility/datastructure/ObjectContainer.java =================================================================== --- trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utilities/datastructure/ObjectContainer.java 2010-08-02 20:26:26 UTC (rev 1100) +++ trunk/core/org.cishell.utilities.datastructure/src/org/cishell/utility/datastructure/ObjectContainer.java 2010-08-05 19:44:07 UTC (rev 1117) @@ -1,4 +1,4 @@ -package org.cishell.utilities.datastructure; +package org.cishell.utility.datastructure; public class ObjectContainer<T> { public T object; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:23:46
|
Revision: 1116 http://cishell.svn.sourceforge.net/cishell/?rev=1116&view=rev Author: pataphil Date: 2010-08-05 19:23:40 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Changed org.cishell.utilities.swt to org.cishell.utility.swt. Added Paths: ----------- trunk/core/org.cishell.utility.swt/ Removed Paths: ------------- trunk/core/org.cishell.utilities.swt/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:14:12
|
Revision: 1115 http://cishell.svn.sourceforge.net/cishell/?rev=1115&view=rev Author: pataphil Date: 2010-08-05 19:14:06 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Attempting to fix build. Modified Paths: -------------- trunk/deployment/org.cishell.reference.database.feature/feature.xml trunk/deployment/org.cishell.reference.feature/feature.xml trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml Modified: trunk/deployment/org.cishell.reference.database.feature/feature.xml =================================================================== --- trunk/deployment/org.cishell.reference.database.feature/feature.xml 2010-08-05 19:07:24 UTC (rev 1114) +++ trunk/deployment/org.cishell.reference.database.feature/feature.xml 2010-08-05 19:14:06 UTC (rev 1115) @@ -89,6 +89,13 @@ unpack="false"/> <plugin + id="org.cishell.utility.swt" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin id="google_collections" download-size="0" install-size="0" Modified: trunk/deployment/org.cishell.reference.feature/feature.xml =================================================================== --- trunk/deployment/org.cishell.reference.feature/feature.xml 2010-08-05 19:07:24 UTC (rev 1114) +++ trunk/deployment/org.cishell.reference.feature/feature.xml 2010-08-05 19:14:06 UTC (rev 1115) @@ -115,6 +115,13 @@ unpack="false"/> <plugin + id="org.cishell.utility.swt" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin id="org.cishell.algorithm.convertergraph" download-size="0" install-size="0" Modified: trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml =================================================================== --- trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2010-08-05 19:07:24 UTC (rev 1114) +++ trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2010-08-05 19:14:06 UTC (rev 1115) @@ -205,8 +205,13 @@ <param name="project.name" value="/core/org.cishell.utilities"/> <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.utility.swt"/> + <param name="project.name" value="/core/org.cishell.utility.swt"/> + <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="google-collections"/> <param name="project.name" value="/libs/google-collections"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:07:30
|
Revision: 1114 http://cishell.svn.sourceforge.net/cishell/?rev=1114&view=rev Author: pataphil Date: 2010-08-05 19:07:24 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Changed org.cishell.utilities.swt to org.cishell.utility.swt. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.log/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogToFile.java trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java Modified: trunk/clients/gui/org.cishell.reference.gui.log/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.log/META-INF/MANIFEST.MF 2010-08-05 19:06:58 UTC (rev 1113) +++ trunk/clients/gui/org.cishell.reference.gui.log/META-INF/MANIFEST.MF 2010-08-05 19:07:24 UTC (rev 1114) @@ -8,5 +8,5 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Eclipse-LazyStart: true -Import-Package: org.cishell.utilities.swt, +Import-Package: org.cishell.utility.swt, org.osgi.service.log;version="1.3.0" Modified: trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogToFile.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogToFile.java 2010-08-05 19:06:58 UTC (rev 1113) +++ trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogToFile.java 2010-08-05 19:07:24 UTC (rev 1114) @@ -2,8 +2,6 @@ import java.io.File; import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.logging.FileHandler; Modified: trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java 2010-08-05 19:06:58 UTC (rev 1113) +++ trunk/clients/gui/org.cishell.reference.gui.log/src/org/cishell/reference/gui/log/LogView.java 2010-08-05 19:07:24 UTC (rev 1114) @@ -24,9 +24,9 @@ import java.util.Map; import java.util.Properties; -import org.cishell.utilities.swt.SWTUtilities; -import org.cishell.utilities.swt.URLClickedListener; -import org.cishell.utilities.swt.URLMouseCursorListener; +import org.cishell.utility.swt.SWTUtilities; +import org.cishell.utility.swt.URLClickedListener; +import org.cishell.utility.swt.URLMouseCursorListener; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.dnd.Clipboard; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 19:07:07
|
Revision: 1113 http://cishell.svn.sourceforge.net/cishell/?rev=1113&view=rev Author: pataphil Date: 2010-08-05 19:06:58 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Changed org.cishell.utilities.swt to org.cishell.utility.swt. Modified Paths: -------------- trunk/core/org.cishell.utilities.swt/.project trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/datasynchronizer/DateDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/datasynchronizer/DropDownDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/datasynchronizer/ModelDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/datasynchronizer/TextDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/datasynchronizer/TimeDataSynchronizer.java Added Paths: ----------- trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/ trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/ trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/ExpandableComponentWidget.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/FileSaveAs.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/GUIBuilderUtilities.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/GUICanceledException.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/GridContainer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/SWTUtilities.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/ScrolledComponentFactory.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/URLClickedListener.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/URLMouseCursorListener.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/ trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/GUIModel.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/GUIModelField.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/GUIModelGroup.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/ModelFieldException.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/model/datasynchronizer/ Removed Paths: ------------- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/ Modified: trunk/core/org.cishell.utilities.swt/.project =================================================================== --- trunk/core/org.cishell.utilities.swt/.project 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/.project 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <projectDescription> - <name>org.cishell.utilities.swt</name> + <name>org.cishell.utility.swt</name> <comment></comment> <projects> </projects> Modified: trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: CIShell SWT Utilities -Bundle-SymbolicName: org.cishell.utilities.swt +Bundle-SymbolicName: org.cishell.utility.swt Bundle-Version: 1.0.0 Bundle-RequiredExecutionEnvironment: J2SE-1.5 Require-Bundle: org.eclipse.ui, @@ -9,6 +9,6 @@ Import-Package: com.google.common.collect, org.cishell.utilities, org.cishell.utilities.datastructure -Export-Package: org.cishell.utilities.swt, - org.cishell.utilities.swt.model, - org.cishell.utilities.swt.model.datasynchronizer +Export-Package: org.cishell.utility.swt, + org.cishell.utility.swt.model, + org.cishell.utility.swt.model.datasynchronizer Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,243 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; - -/** - * This is meant to be subclassed. - */ -public class ExpandableComponentWidget<T> extends Composite { - public static final int COLUMN_AREA_LAYOUT_VERTICAL_SPACING = 1; - public static final int VERTICAL_SCROLL_INCREMENT = 50; - - private ScrolledComponentFactory<T> componentFactory; - private Composite headerArea; - private ScrolledComposite scrollingArea; - private GridContainer scrolledAreaGrid; - private Composite footerArea; - private List<T> components = new ArrayList<T>(); - private int uniqueComponentCount = 0; - private Collection<Label> columnLabels; - - public ExpandableComponentWidget( - Composite parent, ScrolledComponentFactory<T> componentFactory) { - super(parent, SWT.NONE); - this.componentFactory = componentFactory; - - setLayout(createLayout()); - this.headerArea = createHeaderArea(); - this.scrollingArea = createScrollingArea(); - this.footerArea = createFooterArea(); - this.scrolledAreaGrid = createScrolledAreaGrid(this.scrollingArea); - - this.scrollingArea.setExpandHorizontal(true); - this.scrollingArea.setExpandVertical(true); - this.scrollingArea.setAlwaysShowScrollBars(true); - fixSize(); - this.scrollingArea.setContent(this.scrolledAreaGrid.getActualParent()); - this.scrollingArea.getVerticalBar().setPageIncrement(VERTICAL_SCROLL_INCREMENT); - this.columnLabels = createColumnLabels(this.scrolledAreaGrid.getActualParent(), SWT.NONE); - } - - public Composite getHeaderArea() { - return this.headerArea; - } - - public Composite getFooterArea() { - return this.footerArea; - } - - public List<T> getComponents() { - return Collections.unmodifiableList(this.components); - } - - public int getColumnCount() { - return 1; - } - - public T addComponent(int style, Map<String, Object> arguments) { - // TODO: Fix this terrible hack? - if (this.components.size() == 0) { - for (Label columnLabel : this.columnLabels) { - columnLabel.setVisible(true); - } - } - - final int componentCount = this.components.size(); - T component = this.componentFactory.constructWidget( - this, this.scrolledAreaGrid, style, arguments, componentCount, this.uniqueComponentCount); - this.uniqueComponentCount++; - - fixSize(); - - this.components.add(component); - - return component; - } - - public void removeComponent(int index) { - this.scrolledAreaGrid.removeRow(index); - this.components.remove(index); - fixSize(); - - for (int ii = 0; ii < this.components.size(); ii++) { - this.componentFactory.reindexComponent(this.components.get(ii), ii); - } - - // TODO: Fix this terrible hack? - if (this.components.size() == 0) { - for (Label columnLabel : this.columnLabels) { - columnLabel.setVisible(false); - } - } - } - - public Collection<Label> createColumnLabels(Composite parent, int style) { - List<Label> columnLabels = new ArrayList<Label>(); - - for (String columnLabelText : createColumnLabelTexts()) { - Label columnLabel = new Label(parent, style); - columnLabel.setLayoutData(createColumnLabelLayoutData()); - columnLabel.setText(columnLabelText); - columnLabels.add(columnLabel); - } - - return columnLabels; - } - - public Collection<String> createColumnLabelTexts() { - List<String> columnLabelTexts = new ArrayList<String>(); - - for (int ii = 0; ii < getColumnCount(); ii++) { - columnLabelTexts.add("Column " + ii); - } - - return columnLabelTexts; - } - - private void fixSize() { - Composite scrolledArea = this.scrolledAreaGrid.getActualParent(); - this.scrollingArea.setMinSize(scrolledArea.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - scrolledArea.pack(); - } - - protected Composite createHeaderArea() { - Composite headerArea = new Composite(this, SWT.NONE); - headerArea.setLayoutData(createHeaderAreaLayoutData()); - headerArea.setLayout(createHeaderLayout()); - - return headerArea; - } - - protected GridData createHeaderAreaLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); - - return layoutData; - } - - protected GridLayout createHeaderLayout() { - GridLayout layout = new GridLayout(1, false); - GUIBuilderUtilities.clearMargins(layout); - GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } - - protected ScrolledComposite createScrollingArea() { - ScrolledComposite scrollingArea = - new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL); - scrollingArea.setLayoutData(createScrollingAreaLayoutData()); - scrollingArea.setLayout(createScrollingLayout()); - - return scrollingArea; - } - - protected GridData createScrollingAreaLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); - - return layoutData; - } - - private GridLayout createScrollingLayout() { - GridLayout layout = new GridLayout(1, true); - GUIBuilderUtilities.clearMargins(layout); - GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } - - protected Composite createFooterArea() { - Composite footerArea = new Composite(this, SWT.BORDER); - footerArea.setLayoutData(createFooterAreaLayoutData()); - footerArea.setLayout(createFooterLayout()); - - return footerArea; - } - - protected GridData createFooterAreaLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); - - return layoutData; - } - - protected GridLayout createFooterLayout() { - GridLayout layout = new GridLayout(1, false); - GUIBuilderUtilities.clearMargins(layout); - GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } - - private GridContainer createScrolledAreaGrid(Composite parent) { - Composite columnArea = new Composite(parent, SWT.NONE); - columnArea.setLayoutData(createScrolledAreaLayoutData()); - final int columnCount = getColumnCount(); - columnArea.setLayout(createScrolledAreaLayout(columnCount)); - - return new GridContainer(columnArea, columnCount); - } - - protected GridData createScrolledAreaLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); - - return layoutData; - } - - protected GridLayout createScrolledAreaLayout(int columnCount) { - GridLayout layout = new GridLayout(columnCount, false); -// GUIBuilderUtilities.clearMargins(layout); -// GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } - - protected GridData createColumnLabelLayoutData() { - GridData layoutData = new GridData(SWT.CENTER, SWT.CENTER, false, false); - - return layoutData; - } - - protected GridData createComponentLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); - - return layoutData; - } - - private static GridLayout createLayout() { - GridLayout layout = new GridLayout(1, true); - GUIBuilderUtilities.clearMargins(layout); - GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,52 +0,0 @@ -package org.cishell.utilities.swt; - -import java.io.File; - -import org.cishell.utilities.StringUtilities; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; - -public class FileSaveAs { - public static final String DEFAULT_WINDOW_TITLE = "Save As"; - public static final String CONFIRMATION_DIALOG_FORMAT = - "%s already exists.\nDo you want to replace it?"; -// public static final String YES_BUTTON_LABEL = "Yes"; -// public static final String NO_BUTTON_LABEL = "No"; -// public static final String[] BUTTON_LABELS = { YES_BUTTON_LABEL, NO_BUTTON_LABEL }; - - public static String saveFileAs(Shell parent) { - FileDialog saveDialog = new FileDialog(parent); - saveDialog.setText(DEFAULT_WINDOW_TITLE); - - return saveFileAs(saveDialog); - } - - public static String saveFileAs(Shell parent, int style) { - FileDialog saveDialog = new FileDialog(parent, style); - saveDialog.setText(DEFAULT_WINDOW_TITLE); - - return saveFileAs(saveDialog); - } - - public static String saveFileAs(FileDialog saveDialog) { - while (true) { - String selectedFilePath = saveDialog.open(); - - if (StringUtilities.isNull_Empty_OrWhitespace(selectedFilePath)) { - return null; - } else { - if (new File(selectedFilePath).exists()) { - if (MessageDialog.openConfirm( - saveDialog.getParent(), - saveDialog.getText(), - String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath))) { - return selectedFilePath; - } - } else { - return selectedFilePath; - } - } - } - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,124 +0,0 @@ -package org.cishell.utilities.swt; - -import org.cishell.utilities.datastructure.ObjectContainer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ShellEvent; -import org.eclipse.swt.events.ShellListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; - -public class GUIBuilderUtilities { - public static Display createDisplay() { - return new Display(); - } - - public static Shell createShell( - Display display, - String windowTitle, - int windowWidth, - int windowHeight, - int columnCount, - boolean clearSpacing) { - Shell shell = new Shell(display, SWT.CLOSE | SWT.MIN | SWT.TITLE); - shell.setText(windowTitle); - shell.setSize(windowWidth, windowHeight); - shell.setLayout(createShellLayout(columnCount, clearSpacing)); - - return shell; - } - - public static GridLayout createShellLayout(int columnCount, boolean clearSpacing) { - GridLayout layout = new GridLayout(columnCount, true); - - if (clearSpacing) { - clearSpacing(layout); - } - - return layout; - } - - public static void openShell( - Shell shell, int windowHeight, boolean useWindowHeightToSizeShell) { -// if (useWindowHeightToSizeShell) { -// /* (So far, we've created the shell at the maximum possible size we'll allow -// * (according to windowHeight). This line shrinks the shell to be a more fitting size -// * if the actual contents (i.e. our (number of) columns) are smaller than the maximum -// * size we set.) -// */ -// Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); -// shell.setMinimumSize(shellSize.x, Math.min(windowHeight, shellSize.y)); -// } - - shell.pack(); - shell.open(); - - if (useWindowHeightToSizeShell) { - Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); - shell.setSize(shell.getSize().x, Math.min(windowHeight, shellSize.y)); - } - } - - public static void swtLoop(Display display, Shell shell) { - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - display.dispose(); - } - - public static void clearMargins(GridLayout layout) { - layout.marginTop = layout.marginBottom = layout.marginHeight = 0; - layout.marginLeft = layout.marginRight = layout.marginWidth = 0; - } - - public static void clearSpacing(GridLayout layout) { - layout.horizontalSpacing = layout.verticalSpacing = 0; - } - - public static void setCancelable( - final Shell shell, final ObjectContainer<GUICanceledException> exceptionThrown) { - shell.addListener(SWT.Traverse, new Listener() { - public void handleEvent(Event event) { - switch (event.detail) { - case SWT.TRAVERSE_ESCAPE: - shell.close(); - event.detail = SWT.TRAVERSE_NONE; - event.doit = false; - -// if (exceptionThrown != null) { -// String exceptionMessage = "Canceled by user."; -// exceptionThrown.object = new GUICanceledException(exceptionMessage); -// } - - break; - } - } - }); - shell.addShellListener(new ShellListener() { - public void shellActivated(ShellEvent event) { - } - - public void shellClosed(ShellEvent event) { - if (exceptionThrown != null) { - String exceptionMessage = "Canceled by user."; - exceptionThrown.object = new GUICanceledException(exceptionMessage); - } - } - - public void shellDeactivated(ShellEvent event) { - } - - public void shellDeiconified(ShellEvent event) { - } - - public void shellIconified(ShellEvent event) { - } - }); - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,21 +0,0 @@ -package org.cishell.utilities.swt; - -public class GUICanceledException extends Exception { - private static final long serialVersionUID = 1L; - - public GUICanceledException() { - super(); - } - - public GUICanceledException(String arg0) { - super(arg0); - } - - public GUICanceledException(Throwable arg0) { - super(arg0); - } - - public GUICanceledException(String arg0, Throwable arg1) { - super(arg0, arg1); - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,92 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Widget; - -public class GridContainer { - private Composite actualParent; - private int columnCount; - private List<GridRow> rows = new ArrayList<GridRow>(); - - public GridContainer(Composite actualParent, int columnCount) { - this.actualParent = actualParent; - this.columnCount = columnCount; - } - - public Composite getActualParent() { - return this.actualParent; - } - - public int getColumnCount() { - return this.columnCount; - } - - public int getRowCount() { - return this.rows.size(); - } - - public GridRow addComponent(Widget component) { - GridRow lastRow = getOrCreateLastUsableRow(); - lastRow.addComponent(component); - - return lastRow; - } - - public void removeRow(int rowIndex) { - this.rows.get(rowIndex).dispose(); - this.rows.remove(rowIndex); - } - - private GridRow getOrCreateLastUsableRow() { - final int rowCount = getRowCount(); - - if (rowCount == 0) { - return addNewRow(); - } else { - GridRow lastRow = this.rows.get(rowCount - 1); - - if (lastRow.componentCount < getColumnCount()) { - return lastRow; - } else { - return addNewRow(); - } - } - } - - private GridRow addNewRow() { - GridRow row = new GridRow(getRowCount()); - this.rows.add(row); - - return row; - } - - public class GridRow { - private int rowIndex; - private int componentCount = 0; - private Collection<Widget> components = - new ArrayList<Widget>(GridContainer.this.columnCount); - - private GridRow(int rowIndex) { - this.rowIndex = rowIndex; - } - - public int getRowIndex() { - return this.rowIndex; - } - - private void addComponent(Widget component) { - this.components.add(component); - this.componentCount++; - } - - private void dispose() { - for (Widget component : this.components) { - component.dispose(); - } - } - } -} Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,123 +0,0 @@ -package org.cishell.utilities.swt; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; - -public class SWTUtilities { - /* - * Append the given string to the console with the given color, this will do the job of - * checking for URLs within the string and registering the proper listeners on them as well. - */ - public static void appendStringWithURL( - StyledText textField, - URLClickedListener urlListener, - URLMouseCursorListener urlCursorListener, - String message, - Color normalColor, - Color urlColor) { - - //find a URL in the message - - int index = message.indexOf("http://"); - if (index == -1) { - index = message.indexOf("https://"); - } - if (index == -1) { - index = message.indexOf("www."); - } - - if (index > -1) { - String url = message.substring(index); - if (url.indexOf(") ") > -1) { - url = url.substring(0, url.indexOf(") ")); - } - else if (url.indexOf(" ") > -1) { - url = url.substring(0, url.indexOf(" ")); - if (url.trim().endsWith(".") ){ - url=url.substring(0, url.length()-1); - } - } - if (url.endsWith(".\n") || url.endsWith(".\t")){ - url=url.substring(0, url.length()-2); - } - if (url.indexOf("\n") > -1) { - url = url.substring(0, url.indexOf("\n")); - } - if (url.indexOf("\t") > -1) { - url = url.substring(0, url.indexOf("\n")); - } - - - syncedStyledPrint(textField, message.substring(0, index), normalColor, SWT.NORMAL); - urlListener.addURL(textField.getText().length(), url); - urlCursorListener.addURL(textField.getText().length(), url); - syncedStyledPrint(textField, url, urlColor, SWT.BOLD); - appendStringWithURL( - textField, - urlListener, - urlCursorListener, - message.substring(index + url.length()), - normalColor,urlColor); - } else { - syncedStyledPrint(textField, message, normalColor, SWT.NORMAL); - } - } - - /* - * Helper to actually format the string with a style range and - * append it to the StyledText control. - */ - - public static void syncedStyledPrint( - final StyledText textField, final String message, final Color color, final int style) { - Display.getDefault().syncExec(new Runnable() { - public void run(){ - styledPrint(textField, message, color, style); - } - }); - } - - public static void styledPrint(StyledText textField, String message, Color color, int style) { - if (!textField.isDisposed()) { - textField.append(message); - - StyleRange styleRange = new StyleRange(); - styleRange.start = textField.getText().length() - message.length(); - styleRange.length = message.length(); - styleRange.foreground = color; - styleRange.fontStyle = style; - textField.setStyleRange(styleRange); - - // This makes it autoscroll. - textField.setTopIndex(textField.getLineCount()); - } - } - - public static void printURL( - Composite parent, - StyledText textField, - String url, - String displayURL, - Color color, - int style) { - URLClickedListener urlClickedListener = new URLClickedListener(textField); - URLMouseCursorListener urlCursorListener = - new URLMouseCursorListener(parent, textField); - textField.addMouseListener(urlClickedListener); - textField.addMouseMoveListener(urlCursorListener); - - urlClickedListener.addURL( - textField.getText().length(), url, displayURL); - urlCursorListener.addURL( - textField.getText().length(), url, displayURL); - SWTUtilities.styledPrint( - textField, - displayURL, - color, - style); - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,15 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.Map; - -public interface ScrolledComponentFactory<T> { - public T constructWidget( - ExpandableComponentWidget<T> componentWidget, - GridContainer scrolledAreaGrid, - int style, - Map<String, Object> arguments, - int index, - int uniqueIndex); - - public void reindexComponent(T component, int newIndex); -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,70 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.program.Program; - -/* - * Listens for clicks on urls and launches a browser. - */ -public class URLClickedListener extends MouseAdapter { - private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>(); - private Map<String, String> urlsToDisplayURLs = new HashMap<String, String>(); - private StyledText textField; - - public URLClickedListener(StyledText textField) { - super(); - this.textField = textField; - } - - public void addURL(int offset, String url) { - addURL(offset, url, url); - } - - public void addURL(int offset, String url, String displayURL) { - this.offsetsToURLs.put(offset, url); - this.urlsToDisplayURLs.put(url, displayURL); - } - - public void mouseDown(MouseEvent event) { - if (event.button != 1) { - return; - } - - int clickedPosition = determineClickedPosition(event); - - if (clickedPosition < 0) { - return; - } - - for (Integer offset : this.offsetsToURLs.keySet().toArray(new Integer[0])) { - String url = this.offsetsToURLs.get(offset); - String displayURL = this.urlsToDisplayURLs.get(url); - - if ((displayURL != null) && - (clickedPosition >= offset.intValue()) && - (clickedPosition <= (offset.intValue() + displayURL.length()))) { - try { - Program.launch(url); - } catch (Exception e) { - } - } - } - } - - private int determineClickedPosition(MouseEvent event) { - int clickedPosition = -1; - - try { - clickedPosition = this.textField.getOffsetAtLocation(new Point(event.x, event.y)); - } catch (IllegalArgumentException ex) { - } - - return clickedPosition; - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,79 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; - -/* - * Monitors the mouse and changes the cursor when it is over a URL. - */ -public class URLMouseCursorListener implements MouseMoveListener { - private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>(); - private Map<String, String> urlsToDisplayURLs = new HashMap<String, String>(); - private Composite parent; - private StyledText textField; - - public URLMouseCursorListener(Composite parent, StyledText textField) { - this.parent = parent; - this.textField = textField; - } - - public void addURL(int offset, String url) { - addURL(offset, url, url); - } - - public void addURL(int offset, String url, String displayURL) { - this.offsetsToURLs.put(new Integer(offset), url); - this.urlsToDisplayURLs.put(url, displayURL); - } - - public void mouseMove(MouseEvent event) { - int urlOffsetOfMousePosition = determineURLOffsetOfMousePosition(event); - Integer[] urlOffsets = this.offsetsToURLs.keySet().toArray(new Integer[0]); - boolean mouseIsOverURL = determineIfMouseIsHoveringOverURL(urlOffsetOfMousePosition, urlOffsets); - Cursor cursor = new Cursor(parent.getDisplay(), determineMouseCursor(mouseIsOverURL)); - textField.setCursor(cursor); - } - - private int determineURLOffsetOfMousePosition(MouseEvent event) { - try { - return textField.getOffsetAtLocation(new Point(event.x, event.y)); - } catch (IllegalArgumentException e) { - Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW); - textField.setCursor(cursor); - } - - return -1; - } - - private boolean determineIfMouseIsHoveringOverURL( - int urlOffsetOfMousePosition, Integer[] urlOffsets) { - for (Integer urlOffset : urlOffsets) { - String url = this.offsetsToURLs.get(urlOffset); - - if ((urlOffset != null) && - (url != null) && - (urlOffsetOfMousePosition >= urlOffset.intValue()) && - (urlOffsetOfMousePosition <= (urlOffset.intValue() + url.length()))) { - return true; - } - } - - return false; - } - - private int determineMouseCursor(boolean mouseIsOverURL) { - if (mouseIsOverURL) { - return SWT.CURSOR_HAND; - } else { - return SWT.CURSOR_ARROW; - } - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,190 +0,0 @@ -package org.cishell.utilities.swt.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.cishell.utilities.swt.model.datasynchronizer.CheckBoxDataSynchronizer; -import org.cishell.utilities.swt.model.datasynchronizer.DropDownDataSynchronizer; -import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; -import org.cishell.utilities.swt.model.datasynchronizer.SingleListSelectionDataSynchronizer; -import org.cishell.utilities.swt.model.datasynchronizer.TextDataSynchronizer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Widget; - -public class GUIModel { - private Map<String, GUIModelGroup> groups = new HashMap<String, GUIModelGroup>(); - - public GUIModel() { - } - - public Collection<String> getGroupNames() { - return this.groups.keySet(); - } - - public Collection<GUIModelGroup> getGroups() { - return this.groups.values(); - } - - public GUIModelGroup getGroup(String name) { - if (!this.groups.containsKey(name)) { - GUIModelGroup newGroup = new GUIModelGroup(name); - this.groups.put(name, newGroup); - - return newGroup; - } else { - return this.groups.get(name); - } - } - - public GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> addCheckBox( - String groupName, String name, boolean on, Composite parent, int style) { - Button checkBox = new Button(parent, style | SWT.CHECK); - CheckBoxDataSynchronizer dataSynchronizer = new CheckBoxDataSynchronizer(checkBox, on); - GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> field = - new GUIModelField<Boolean, Button, CheckBoxDataSynchronizer>( - name, on, checkBox, dataSynchronizer); - addField(groupName, field); - - return field; - } - - public GUIModelField<String, Combo, DropDownDataSynchronizer> addDropDown( - String groupName, - String name, - int selectedIndex, - Collection<String> unorderedOptionLabels, - Map<String, String> optionValuesByLabels, - Composite parent, - int style) { - java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels); - Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN); - DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer( - dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels); - GUIModelField<String, Combo, DropDownDataSynchronizer> field = - new GUIModelField<String, Combo, DropDownDataSynchronizer>( - name, - optionValuesByLabels.get(orderedOptionLabels.get(selectedIndex)), - dropDown, - dataSynchronizer); - addField(groupName, field); - - return field; - } - - // TODO: addMultiSelectionDropDown - - // TODO: Test this out. - // TODO: Make it so the build works with this stuff. -// public GUIModelField< -// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> -// addDate(String name, org.joda.time.DateTime date, Composite parent, int style) { -// org.eclipse.swt.widgets.DateTime dateSelector = -// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.DATE); -// DateDataSynchronizer dataSynchronizer = new DateDataSynchronizer(dateSelector, date); -// GUIModelField< -// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> field = -// new GUIModelField< -// org.joda.time.DateTime, -// org.eclipse.swt.widgets.DateTime, -// DateDataSynchronizer>( -// name, date, dateSelector, dataSynchronizer); -// addField(field); -// -// return field; -// } - - // TODO: Test this out. -// public GUIModelField< -// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> -// addTime(String name, org.joda.time.DateTime time, Composite parent, int style) { -// org.eclipse.swt.widgets.DateTime timeSelector = -// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.TIME); -// TimeDataSynchronizer dataSynchronizer = new TimeDataSynchronizer(timeSelector, time); -// GUIModelField< -// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> field = -// new GUIModelField< -// org.joda.time.DateTime, -// org.eclipse.swt.widgets.DateTime, -// TimeDataSynchronizer>( -// name, time, timeSelector, dataSynchronizer); -// addField(field); -// -// return field; -// } - - // TODO: addCalendar - - // TODO: Test this out. - public GUIModelField<String, List, SingleListSelectionDataSynchronizer> addList( - String groupName, - String name, - int selectedIndex, - Collection<String> unorderedOptionLabels, - Map<String, String> optionValuesByLabels, - Composite parent, - int style) { - java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels); - List list = new List(parent, style | SWT.SINGLE); - SingleListSelectionDataSynchronizer dataSynchronizer = - new SingleListSelectionDataSynchronizer( - list, selectedIndex, orderedOptionLabels, optionValuesByLabels); - GUIModelField<String, List, SingleListSelectionDataSynchronizer> field = - new GUIModelField<String, List, SingleListSelectionDataSynchronizer>( - name, list.getItem(selectedIndex), list, dataSynchronizer); - addField(groupName, field); - - return field; - } - - // TODO: addMultiSelectionList - // TODO: addProgressBar - // TODO: addSash? - // TODO: addSlider - // TODO: addScale - // TODO: addSpinner - // TODO: addStyledText - - public GUIModelField<String, Text, TextDataSynchronizer> addText( - String groupName, - String name, - String value, - boolean isMultiLined, - Composite parent, - int style) { - if (isMultiLined) { - style = style | SWT.MULTI; - } else { - style = style | SWT.SINGLE; - } - - Text text = new Text(parent, style); - TextDataSynchronizer dataSynchronizer = new TextDataSynchronizer(text, value); - GUIModelField<String, Text, TextDataSynchronizer> field = - new GUIModelField<String, Text, TextDataSynchronizer>( - name, value, text, dataSynchronizer); - addField(groupName, field); - - return field; - } - - public<T> void addField( - String groupName, - GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { - GUIModelGroup group = getGroup(groupName); - group.addField(field); - } - - public<T> void removeField( - GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { - for (GUIModelGroup group : this.groups.values()) { - group.removeField(field); - } - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,65 +0,0 @@ -package org.cishell.utilities.swt.model; - -import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Widget; - -public class GUIModelField<T, U extends Widget, V extends ModelDataSynchronizer<T>> { - private String name; - private T defaultValue; - private T previousValue; - private T value; - private U widget; - private V dataSynchronizer; - - public GUIModelField( - String name, - T defaultValue, - U widget, - V dataSynchronizer) { - this.name = name; - this.defaultValue = defaultValue; - this.value = this.defaultValue; - this.widget = widget; - this.dataSynchronizer = dataSynchronizer; - - this.widget.addListener(this.dataSynchronizer.swtUpdateListenerCode(), new Listener() { - public void handleEvent(Event event) { - if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) { - GUIModelField.this.previousValue = GUIModelField.this.value; - GUIModelField.this.value = - GUIModelField.this.dataSynchronizer.synchronizeFromGUI(); - } - } - }); - } - - public String getName() { - return this.name; - } - - public T getPreviousValue() { - return this.previousValue; - } - - public T getValue() { - return this.value; - } - - public U getWidget() { - return this.widget; - } - - public V getDataSynchronizer() { - return this.dataSynchronizer; - } - - public void setValue(T value) { - this.value = this.dataSynchronizer.synchronizeToGUI(value); - } - - public void reset() { - this.value = this.dataSynchronizer.reset(this.defaultValue); - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,57 +0,0 @@ -package org.cishell.utilities.swt.model; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; -import org.eclipse.swt.widgets.Widget; - -public class GUIModelGroup { - private String name; - private Map<String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> - inputFieldsByName = new HashMap< - String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>(); - - public GUIModelGroup(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - public Collection<String> getFieldNames() { - return this.inputFieldsByName.keySet(); - } - - public Collection< - GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> getFields() { - return this.inputFieldsByName.values(); - } - - public GUIModelField< - ?, ? extends Widget, ? extends ModelDataSynchronizer<?>> getField(String name) { - return this.inputFieldsByName.get(name); - } - - public<T> void addField( - GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { - String fieldName = field.getName(); - - if (this.inputFieldsByName.containsKey(fieldName)) { - String exceptionMessage = - "A field with the name \"" + fieldName + "\" already exists. Unable to continue."; - throw new ModelFieldException(exceptionMessage); - } - - this.inputFieldsByName.put(fieldName, field); - } - - public<T> void removeField( - GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { - if (this.inputFieldsByName.containsValue(field)) { - this.inputFieldsByName.remove(field.getName()); - } - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java 2010-08-05 18:59:05 UTC (rev 1112) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -1,21 +0,0 @@ -package org.cishell.utilities.swt.model; - -public class ModelFieldException extends RuntimeException { - private static final long serialVersionUID = 1L; - - public ModelFieldException() { - super(); - } - - public ModelFieldException(String arg0) { - super(arg0); - } - - public ModelFieldException(Throwable arg0) { - super(arg0); - } - - public ModelFieldException(String arg0, Throwable arg1) { - super(arg0, arg1); - } -} \ No newline at end of file Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/ExpandableComponentWidget.java (from rev 1105, trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/ExpandableComponentWidget.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/ExpandableComponentWidget.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -0,0 +1,243 @@ +package org.cishell.utility.swt; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +/** + * This is meant to be subclassed. + */ +public class ExpandableComponentWidget<T> extends Composite { + public static final int COLUMN_AREA_LAYOUT_VERTICAL_SPACING = 1; + public static final int VERTICAL_SCROLL_INCREMENT = 50; + + private ScrolledComponentFactory<T> componentFactory; + private Composite headerArea; + private ScrolledComposite scrollingArea; + private GridContainer scrolledAreaGrid; + private Composite footerArea; + private List<T> components = new ArrayList<T>(); + private int uniqueComponentCount = 0; + private Collection<Label> columnLabels; + + public ExpandableComponentWidget( + Composite parent, ScrolledComponentFactory<T> componentFactory) { + super(parent, SWT.NONE); + this.componentFactory = componentFactory; + + setLayout(createLayout()); + this.headerArea = createHeaderArea(); + this.scrollingArea = createScrollingArea(); + this.footerArea = createFooterArea(); + this.scrolledAreaGrid = createScrolledAreaGrid(this.scrollingArea); + + this.scrollingArea.setExpandHorizontal(true); + this.scrollingArea.setExpandVertical(true); + this.scrollingArea.setAlwaysShowScrollBars(true); + fixSize(); + this.scrollingArea.setContent(this.scrolledAreaGrid.getActualParent()); + this.scrollingArea.getVerticalBar().setPageIncrement(VERTICAL_SCROLL_INCREMENT); + this.columnLabels = createColumnLabels(this.scrolledAreaGrid.getActualParent(), SWT.NONE); + } + + public Composite getHeaderArea() { + return this.headerArea; + } + + public Composite getFooterArea() { + return this.footerArea; + } + + public List<T> getComponents() { + return Collections.unmodifiableList(this.components); + } + + public int getColumnCount() { + return 1; + } + + public T addComponent(int style, Map<String, Object> arguments) { + // TODO: Fix this terrible hack? + if (this.components.size() == 0) { + for (Label columnLabel : this.columnLabels) { + columnLabel.setVisible(true); + } + } + + final int componentCount = this.components.size(); + T component = this.componentFactory.constructWidget( + this, this.scrolledAreaGrid, style, arguments, componentCount, this.uniqueComponentCount); + this.uniqueComponentCount++; + + fixSize(); + + this.components.add(component); + + return component; + } + + public void removeComponent(int index) { + this.scrolledAreaGrid.removeRow(index); + this.components.remove(index); + fixSize(); + + for (int ii = 0; ii < this.components.size(); ii++) { + this.componentFactory.reindexComponent(this.components.get(ii), ii); + } + + // TODO: Fix this terrible hack? + if (this.components.size() == 0) { + for (Label columnLabel : this.columnLabels) { + columnLabel.setVisible(false); + } + } + } + + public Collection<Label> createColumnLabels(Composite parent, int style) { + List<Label> columnLabels = new ArrayList<Label>(); + + for (String columnLabelText : createColumnLabelTexts()) { + Label columnLabel = new Label(parent, style); + columnLabel.setLayoutData(createColumnLabelLayoutData()); + columnLabel.setText(columnLabelText); + columnLabels.add(columnLabel); + } + + return columnLabels; + } + + public Collection<String> createColumnLabelTexts() { + List<String> columnLabelTexts = new ArrayList<String>(); + + for (int ii = 0; ii < getColumnCount(); ii++) { + columnLabelTexts.add("Column " + ii); + } + + return columnLabelTexts; + } + + private void fixSize() { + Composite scrolledArea = this.scrolledAreaGrid.getActualParent(); + this.scrollingArea.setMinSize(scrolledArea.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + scrolledArea.pack(); + } + + protected Composite createHeaderArea() { + Composite headerArea = new Composite(this, SWT.NONE); + headerArea.setLayoutData(createHeaderAreaLayoutData()); + headerArea.setLayout(createHeaderLayout()); + + return headerArea; + } + + protected GridData createHeaderAreaLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); + + return layoutData; + } + + protected GridLayout createHeaderLayout() { + GridLayout layout = new GridLayout(1, false); + GUIBuilderUtilities.clearMargins(layout); + GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } + + protected ScrolledComposite createScrollingArea() { + ScrolledComposite scrollingArea = + new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL); + scrollingArea.setLayoutData(createScrollingAreaLayoutData()); + scrollingArea.setLayout(createScrollingLayout()); + + return scrollingArea; + } + + protected GridData createScrollingAreaLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + + return layoutData; + } + + private GridLayout createScrollingLayout() { + GridLayout layout = new GridLayout(1, true); + GUIBuilderUtilities.clearMargins(layout); + GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } + + protected Composite createFooterArea() { + Composite footerArea = new Composite(this, SWT.BORDER); + footerArea.setLayoutData(createFooterAreaLayoutData()); + footerArea.setLayout(createFooterLayout()); + + return footerArea; + } + + protected GridData createFooterAreaLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); + + return layoutData; + } + + protected GridLayout createFooterLayout() { + GridLayout layout = new GridLayout(1, false); + GUIBuilderUtilities.clearMargins(layout); + GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } + + private GridContainer createScrolledAreaGrid(Composite parent) { + Composite columnArea = new Composite(parent, SWT.NONE); + columnArea.setLayoutData(createScrolledAreaLayoutData()); + final int columnCount = getColumnCount(); + columnArea.setLayout(createScrolledAreaLayout(columnCount)); + + return new GridContainer(columnArea, columnCount); + } + + protected GridData createScrolledAreaLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + + return layoutData; + } + + protected GridLayout createScrolledAreaLayout(int columnCount) { + GridLayout layout = new GridLayout(columnCount, false); +// GUIBuilderUtilities.clearMargins(layout); +// GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } + + protected GridData createColumnLabelLayoutData() { + GridData layoutData = new GridData(SWT.CENTER, SWT.CENTER, false, false); + + return layoutData; + } + + protected GridData createComponentLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); + + return layoutData; + } + + private static GridLayout createLayout() { + GridLayout layout = new GridLayout(1, true); + GUIBuilderUtilities.clearMargins(layout); + GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } +} \ No newline at end of file Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/FileSaveAs.java (from rev 1105, trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/FileSaveAs.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/FileSaveAs.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -0,0 +1,52 @@ +package org.cishell.utility.swt; + +import java.io.File; + +import org.cishell.utilities.StringUtilities; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; + +public class FileSaveAs { + public static final String DEFAULT_WINDOW_TITLE = "Save As"; + public static final String CONFIRMATION_DIALOG_FORMAT = + "%s already exists.\nDo you want to replace it?"; +// public static final String YES_BUTTON_LABEL = "Yes"; +// public static final String NO_BUTTON_LABEL = "No"; +// public static final String[] BUTTON_LABELS = { YES_BUTTON_LABEL, NO_BUTTON_LABEL }; + + public static String saveFileAs(Shell parent) { + FileDialog saveDialog = new FileDialog(parent); + saveDialog.setText(DEFAULT_WINDOW_TITLE); + + return saveFileAs(saveDialog); + } + + public static String saveFileAs(Shell parent, int style) { + FileDialog saveDialog = new FileDialog(parent, style); + saveDialog.setText(DEFAULT_WINDOW_TITLE); + + return saveFileAs(saveDialog); + } + + public static String saveFileAs(FileDialog saveDialog) { + while (true) { + String selectedFilePath = saveDialog.open(); + + if (StringUtilities.isNull_Empty_OrWhitespace(selectedFilePath)) { + return null; + } else { + if (new File(selectedFilePath).exists()) { + if (MessageDialog.openConfirm( + saveDialog.getParent(), + saveDialog.getText(), + String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath))) { + return selectedFilePath; + } + } else { + return selectedFilePath; + } + } + } + } +} \ No newline at end of file Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/GUIBuilderUtilities.java (from rev 1105, trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/GUIBuilderUtilities.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utility/swt/GUIBuilderUtilities.java 2010-08-05 19:06:58 UTC (rev 1113) @@ -0,0 +1,124 @@ +package org.cishell.utility.swt; + +import org.cishell.utilities.datastructure.ObjectContainer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.events.ShellListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; + +public class GUIBuilderUtilities { + public static Display createDisplay() { + return new Display(); + } + + public static Shell createShell( + Display display, + String windowTitle, + int windowWidth, + int windowHeight, + int columnCount, + boolean clearSpacing) { + Shell shell = new Shell(display, SWT.CLOSE | SWT.MIN | SWT.TITLE); + shell.setText(windowTitle); + shell.setSize(windowWidth, windowHeight); + shell.setLayout(createShellLayout(columnCount, clearSpacing)); + + return shell; + } + + public static GridLayout createShellLayout(int columnCount, boolean clearSpacing) { + GridLayout layout = new GridLayout(columnCount, true); + + if (clearSpacing) { + clearSpacing(layout); + } + + return layout; + } + + public static void openShell( + Shell shell, int windowHeight, boolean useWindowHeightToSizeShell) { +// if (useWindowHeightToSizeShell) { +// /* (So far, we've created the shell at the maximum possible size we'll allow +// * (according to windowHeight). This line shrinks the shell to be a more fitting size +// * if the actual contents (i.e. our (number of) columns) are smaller than the maximum +// * size we set.) +// */ +// Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); +// shell.setMinimumSize(shellSize.x, Math.min(windowHeight, shellSize.y)); +// } + + shell.pack(); + shell.open(); + + if (useWindowHeightToSizeShell) { + Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); + shell.setSize(shell.getSize().x, Math.min(windowHeight, shellSize.y)); + } + } + + public static void swtLoop(Display display, Shell shell) { + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + display.dispose(); + } + + public static void clearMargins(GridLayout layout) { + layout.marginTop = layout.marginBottom = layout.marginHeight = 0; + layout.marginLeft = layout.marginRight = layout.marginWidth = 0; + } + + public static void clearSpacing(GridLayout layout) { + layout.horizontalSpacing = layout.verticalSpacing = 0; + } + + public static void setCancelable( + final Shell shell, final ObjectContainer<GUICanceledException> exceptionThrown) { + shell.addListener(SWT.Traverse, new Listener() { + public void handleEvent(Event event) { + switch (event.detail) { + case SWT.TRAVERSE_ESCAPE: + shell.close(); + event.detail = SWT.TRAVERSE_NONE; + event.doit = false; + +// if (exceptionThrown != null) { +// String exceptionMessage = "Canceled by user."; +// exceptionThrown.object = new GUICanceledException(exceptionMessage); +// } + + break; + } + } + }); + shell.addShellListener(new ShellListener() { + public void shellActivated(ShellEvent event) { + } + + public void shellClosed(ShellEvent event) { + if (exceptionThrown != null) { + String exceptionMessage = "Canceled by user."; + exceptionThrown.object = new GUICanceledException(except... [truncated message content] |
From: <pat...@us...> - 2010-08-05 18:59:14
|
Revision: 1112 http://cishell.svn.sourceforge.net/cishell/?rev=1112&view=rev Author: pataphil Date: 2010-08-05 18:59:05 +0000 (Thu, 05 Aug 2010) Log Message: ----------- Fixed StringUtilities.getAllTokens(). 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 2010-08-05 16:20:09 UTC (rev 1111) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-08-05 18:59:05 UTC (rev 1112) @@ -1,12 +1,16 @@ package org.cishell.utilities; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; +import java.util.regex.Pattern; public class StringUtilities { + public static Pattern NON_ALPHA_NUMERIC_CHARACTER_ESCAPE = Pattern.compile("([^a-zA-z0-9])"); + // TODO: Make this wrap implodeItems. public static String implodeStringArray(String[] stringArray, String separator) { final int stringArrayLength = stringArray.length; @@ -318,7 +322,8 @@ public static String[] getAllTokens( String originalString, String separator, boolean trim) { - String[] tokens = originalString.split(separator); + String escapedSeparator = escapeForRegularExpression(separator); + String[] tokens = originalString.split(escapedSeparator); if (trim) { String[] trimmedTokens = new String[tokens.length]; @@ -358,6 +363,10 @@ } } + public static String escapeForRegularExpression(String original) { + return NON_ALPHA_NUMERIC_CHARACTER_ESCAPE.matcher(original).replaceAll("\\\\$1"); + } + // TODO // public static String escape(String unescaped) { // return unescaped.replaceAll("\"", "\\\"" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 16:20:18
|
Revision: 1111 http://cishell.svn.sourceforge.net/cishell/?rev=1111&view=rev Author: pataphil Date: 2010-08-05 16:20:09 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Removed an unneeded version dependency for SWT. Modified Paths: -------------- trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF Modified: trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-05 16:13:52 UTC (rev 1110) +++ trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-05 16:20:09 UTC (rev 1111) @@ -4,8 +4,8 @@ Bundle-SymbolicName: org.cishell.utilities.swt Bundle-Version: 1.0.0 Bundle-RequiredExecutionEnvironment: J2SE-1.5 -Require-Bundle: org.eclipse.ui;bundle-version="3.4.1", - org.eclipse.core.runtime;bundle-version="3.4.0" +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime Import-Package: com.google.common.collect, org.cishell.utilities, org.cishell.utilities.datastructure This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 16:13:58
|
Revision: 1110 http://cishell.svn.sourceforge.net/cishell/?rev=1110&view=rev Author: pataphil Date: 2010-08-05 16:13:52 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Removed an unneeded package declaration. Removed Paths: ------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-05 13:43:38
|
Revision: 1109 http://cishell.svn.sourceforge.net/cishell/?rev=1109&view=rev Author: pataphil Date: 2010-08-05 13:43:32 +0000 (Thu, 05 Aug 2010) Log Message: ----------- * Removed an unneeded dependency. Modified Paths: -------------- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-08-03 19:15:24 UTC (rev 1108) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-08-05 13:43:32 UTC (rev 1109) @@ -12,7 +12,6 @@ org.cishell.framework.data, org.cishell.reference.service.metatype, org.cishell.service.database, - org.cishell.utilities.datastructure, org.joda.time, org.joda.time.base, org.joda.time.chrono, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-03 19:15:32
|
Revision: 1108 http://cishell.svn.sourceforge.net/cishell/?rev=1108&view=rev Author: pataphil Date: 2010-08-03 19:15:24 +0000 (Tue, 03 Aug 2010) Log Message: ----------- * Cleaned up and refactored a bit of code. * Introduced the notion of the Algorithm Invocation Service, though it's commented out. * Reviewed by Micah. Modified Paths: -------------- trunk/core/org.cishell.framework/src/org/cishell/app/service/scheduler/SchedulerService.java trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationCanceledException.java trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationFailedException.java trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory.java trunk/core/org.cishell.framework/src/org/cishell/framework/data/BasicData.java trunk/core/org.cishell.framework/src/org/cishell/framework/data/Data.java trunk/core/org.cishell.reference/.settings/org.eclipse.jdt.core.prefs trunk/core/org.cishell.reference/META-INF/MANIFEST.MF trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/scheduler/SchedulerServiceImpl.java trunk/core/org.cishell.reference.services/src/org/cishell/reference/services/Activator.java Added Paths: ----------- trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/ trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java Modified: trunk/core/org.cishell.framework/src/org/cishell/app/service/scheduler/SchedulerService.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/app/service/scheduler/SchedulerService.java 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.framework/src/org/cishell/app/service/scheduler/SchedulerService.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -28,7 +28,6 @@ * service as it is not guaranteed to be available like the standard CIShell * services are. * - * @author Bruce Herr (bh...@bh...) */ public interface SchedulerService { /** @@ -37,10 +36,9 @@ * enough resources to fulfill the request. * * @param algorithm The algorithm to be run - * @param ref A reference to the Algorithm's associated service, may - * be <code>null</code> + * @param reference A reference to the Algorithm's associated service, may be <code>null</code> */ - public void runNow(Algorithm algorithm, ServiceReference ref); + public void runNow(Algorithm algorithm, ServiceReference reference); /** * Schedules an Algorithm to be run when convenient. This schedules an @@ -48,10 +46,9 @@ * Algorithms will be scheduled in this way. * * @param algorithm The Algorithm to be scheduled - * @param ref A reference to the Algorithm's associated service, may - * be <code>null</code> + * @param reference A reference to the Algorithm's associated service, may be <code>null</code> */ - public void schedule(Algorithm algorithm, ServiceReference ref); + public void schedule(Algorithm algorithm, ServiceReference reference); /** * Schedules an Algorithm to be run at a specific time. The Algorithm will @@ -60,11 +57,10 @@ * resources to fulfill the request. * * @param algorithm The Algorithm to be scheduled - * @param ref A reference to the Algorithm's associated service, may - * be <code>null</code> + * @param reference A reference to the Algorithm's associated service, may be <code>null</code> * @param time What time this Algorithm should be run */ - public void schedule(Algorithm algorithm, ServiceReference ref, Calendar time); + public void schedule(Algorithm algorithm, ServiceReference reference, Calendar time); /** * Reschedules an already scheduled Algorithm to be run at a different time. Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationCanceledException.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationCanceledException.java 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationCanceledException.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -1,6 +1,5 @@ package org.cishell.framework.algorithm; -// TODO: Make this a regular Exception (not RuntimeException). public class AlgorithmCreationCanceledException extends RuntimeException { private static final long serialVersionUID = 9017277008277139930L; Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationFailedException.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationFailedException.java 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmCreationFailedException.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -1,6 +1,5 @@ package org.cishell.framework.algorithm; -// TODO: Make this a regular Exception (not RuntimeException). public class AlgorithmCreationFailedException extends RuntimeException { private static final long serialVersionUID = 9017277008277139930L; Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory.java 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/algorithm/AlgorithmFactory.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -32,7 +32,6 @@ * CIShell Specification 1.0</a> for documentation on the full requirements for * algorithm creation. * - * @author Bruce Herr (bh...@bh...) */ public interface AlgorithmFactory { @@ -47,7 +46,7 @@ * @param parameters A set of key-value pairs that were created based on * the associated input specification published to the * {@link MetaTypeService} - * @param context The context by which the Algorithm can gain access to + * @param ciShellContext The context by which the Algorithm can gain access to * standard CIShell services * @return An <code>Algorithm</code> primed for execution */ @@ -55,5 +54,5 @@ * the signature, and update the entire code base to conform to it. */ public Algorithm createAlgorithm( - Data[] data, Dictionary<String, Object> parameters, CIShellContext context); + Data[] data, Dictionary<String, Object> parameters, CIShellContext ciShellContext); } Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/data/BasicData.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/data/BasicData.java 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/data/BasicData.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -24,7 +24,7 @@ * @author Bruce Herr (bh...@bh...) */ public class BasicData implements Data { - private Dictionary properties; + private Dictionary<String, Object> properties; private Object data; private String format; @@ -35,7 +35,7 @@ * @param data The data being wrapped */ public BasicData(Object data, String format) { - this(new Hashtable(), data, format); + this(new Hashtable<String, Object>(), data, format); } /** @@ -44,7 +44,7 @@ * @param properties The metadata about the data * @param data The data being wrapped */ - public BasicData(Dictionary properties, Object data, String format) { + public BasicData(Dictionary<String, Object> properties, Object data, String format) { this.properties = properties; this.data = data; this.format = format; @@ -60,7 +60,7 @@ /** * @see org.cishell.framework.data.Data#getMetadata() */ - public Dictionary getMetadata() { + public Dictionary<String, Object> getMetadata() { return properties; } Modified: trunk/core/org.cishell.framework/src/org/cishell/framework/data/Data.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/framework/data/Data.java 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.framework/src/org/cishell/framework/data/Data.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -20,8 +20,7 @@ * A class that contains data, its format, and its metadata. This class is used * to pass data between algorithms and is what algorithms optionally create when * executed. - * - * @author Bruce Herr (bh...@bh...) + * */ public interface Data { /** @@ -30,7 +29,7 @@ * * @return The data's metadata */ - public Dictionary getMetadata(); + public Dictionary<String, Object> getMetadata(); /** * Returns the data stored in this Data object Added: trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java =================================================================== --- trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java (rev 0) +++ trunk/core/org.cishell.framework/src/org/cishell/service/algorithminvocation/AlgorithmInvocationService.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -0,0 +1,126 @@ + +/* TODO: When we have time, we should talk about the design of the Algorithm Invocation Service (if + * we even use that name in the end). + * It's somewhat apparent that there is a use for this service, but exactly how it fits into + * CIShell and all of the tools remains to be fully clarified. + * This is all commented out for now because the design/use need discussion. + */ + +//package org.cishell.service.algorithminvocation; +// +//import java.util.Dictionary; +// +//import org.cishell.framework.CIShellContext; +//import org.cishell.framework.algorithm.Algorithm; +//import org.cishell.framework.algorithm.AlgorithmCanceledException; +//import org.cishell.framework.algorithm.AlgorithmCreationCanceledException; +//import org.cishell.framework.algorithm.AlgorithmCreationFailedException; +//import org.cishell.framework.algorithm.AlgorithmExecutionException; +//import org.cishell.framework.algorithm.AlgorithmFactory; +//import org.cishell.framework.data.Data; +// +///** +// * Provides the caller with various ways of creating algorithms, executing them, and +// * gathering/mutating parameters. +// * When creating an algorithm (from a factory), if the factory implements ParameterMutator, +// * mutateParameters() will be called on it. +// * All methods can optionally operate on a new thread, which is determined by shouldUseNewThread. +// */ +//public interface AlgorithmInvocationService { +// /** +// * Uses factory to create an algorithm, presenting the user with a GUI for parameters. +// */ +// public Algorithm createAlgorithm( +// final AlgorithmFactory factory, +// final Data[] data, +// final CIShellContext ciShellContext, +// boolean shouldUseNewThread) +// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException; +// +// /** +// * Uses factory to create an algorithm, using parameters (instead of presenting the user with a +// * GUI for them). +// */ +// public Algorithm createAlgorithm( +// final AlgorithmFactory factory, +// final Data[] data, +// final Dictionary<String, Object> parameters, +// final CIShellContext ciShellContext, +// boolean shouldUseNewThread) +// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException; +// +// /** +// * Invokes algorithm, returning the Data[] result of algorithm.execute(). +// * If logExceptionThrown is true, any exception thrown will be logged to the +// * default LogService. +// * If displayRuntimeException is true, the stack trace of any exception thrown will be +// * displayed in an error message box. +// */ +// public Data[] invokeAlgorithm( +// final Algorithm algorithm, +// final boolean logExceptionThrown, +// final boolean displayRuntimeException, +// boolean shouldUseNewThread) +// throws AlgorithmCanceledException, AlgorithmExecutionException; +// +// /** +// * Invokes algorithm, assuming sensible defaults for inline algorithm execution (that is, +// * not explicitly invoked from a menu/etc.), and return the Data[] result of +// * algorithm.execute(). +// * Most likely wraps invokeAlgorithm(). +// */ +// public Data[] simpleInvokeAlgorithm(final Algorithm algorithm, Thread thread) +// throws AlgorithmCanceledException, AlgorithmExecutionException; +// +// /** +// * Given factory, presents the user with a GUI for parameters to use for creating and executing +// * an algorithm. +// * Most likely wraps createAlgorithm() and invokeAlgorithm(). +// */ +// public Data[] createAndInvokeAlgorithm( +// final AlgorithmFactory factory, +// final Data[] data, +// final CIShellContext ciShellContext, +// final boolean logExceptionThrown, +// final boolean displayRuntimeException, +// boolean shouldUseNewThread) throws +// AlgorithmCreationCanceledException, +// AlgorithmCreationFailedException, +// AlgorithmCanceledException, +// AlgorithmExecutionException; +// +// /** +// * Given factory, uses parameters to create and execute an algorithm. +// * Most likely wraps createAlgorithm() and invokeAlgorithm(). +// */ +// public Data[] createAndInvokeAlgorithm( +// final AlgorithmFactory factory, +// final Data[] data, +// final Dictionary<String, Object> parameters, +// final CIShellContext ciShellContext, +// final boolean logExceptionThrown, +// final boolean displayRuntimeException, +// boolean shouldUseNewThread) throws +// AlgorithmCreationCanceledException, +// AlgorithmCreationFailedException, +// AlgorithmCanceledException, +// AlgorithmExecutionException; +// +// /** +// * Given factory, uses parameters to create and execute an algorithm. +// * Sensible defaults for inline algorithm execution (that is, not explicitly invoked from a +// * menu/etc.) are used. +// * Returns the Data[] result of algorithm.execute(). +// * Most likely wraps createAlgorithm() and simpleInvokeAlgorithm(). +// */ +// public Data[] simpleCreateAndInvokeAlgorithm( +// final AlgorithmFactory factory, +// final Data[] data, +// final Dictionary<String, Object> parameters, +// CIShellContext ciShellContext, +// boolean shouldUseNewThread) throws +// AlgorithmCreationCanceledException, +// AlgorithmCreationFailedException, +// AlgorithmCanceledException, +// AlgorithmExecutionException; +//} \ No newline at end of file Modified: trunk/core/org.cishell.reference/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/core/org.cishell.reference/.settings/org.eclipse.jdt.core.prefs 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.reference/.settings/org.eclipse.jdt.core.prefs 2010-08-03 19:15:24 UTC (rev 1108) @@ -1,12 +1,12 @@ -#Mon Jul 27 15:45:33 EDT 2009 +#Wed Jul 21 20:42:37 EDT 2010 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 Modified: trunk/core/org.cishell.reference/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.reference/META-INF/MANIFEST.MF 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.reference/META-INF/MANIFEST.MF 2010-08-03 19:15:24 UTC (rev 1108) @@ -1,4 +1,3 @@ -Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: CIShell Reference Service Implementations Bundle-SymbolicName: org.cishell.reference @@ -14,9 +13,11 @@ org.osgi.service.log, org.osgi.service.metatype;version="1.1.0", org.osgi.service.prefs -Export-Package: org.cishell.reference.app.service.datamanager, +Export-Package: org.cishell.reference.app.service.algorithminvocation, + org.cishell.reference.app.service.datamanager, org.cishell.reference.app.service.scheduler, org.cishell.reference.service.conversion, org.cishell.reference.service.metatype Eclipse-LazyStart: true Require-Bundle: edu.uci.ics.jung +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Added: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java (rev 0) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/algorithminvocation/AlgorithmInvocationServiceImpl.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -0,0 +1,85 @@ +//package org.cishell.reference.app.service.algorithminvocation; +// +//import java.util.Dictionary; +//import java.util.Hashtable; +// +//import org.cishell.framework.CIShellContext; +//import org.cishell.framework.algorithm.Algorithm; +//import org.cishell.framework.algorithm.AlgorithmCreationCanceledException; +//import org.cishell.framework.algorithm.AlgorithmCreationFailedException; +//import org.cishell.framework.algorithm.AlgorithmFactory; +//import org.cishell.framework.data.Data; +//import org.cishell.service.algorithminvocation.AlgorithmInvocationService; +//import org.osgi.service.log.LogService; +// +//public class AlgorithmInvocationServiceImpl implements AlgorithmInvocationService { +// private LogService logger; +// +// public AlgorithmInvocationServiceImpl(LogService logger) { +// this.logger = logger; +// } +// +// @SuppressWarnings("unchecked") +// public Algorithm createAlgorithm( +// final AlgorithmFactory factory, +// final Data[] data, +// final CIShellContext ciShellContext, +// boolean shouldUseNewThread) +// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException { +// /* TODO: Refactor org.cishell.utilities into several plugins so there are no +// * circular dependencies! +// */ +// +// final AlgorithmCreationCanceledException[] canceledException = +// new AlgorithmCreationCanceledException[1]; +// final AlgorithmCreationFailedException[] failedException = +// new AlgorithmCreationFailedException[1]; +// final Algorithm[] algorithm = new Algorithm[1]; +// +// Runnable operator = new Runnable() { +// public void run() { +// /* TODO: Refactor algorithm creation code out of +// * org.cishell.reference.gui.menumanager, and call it here. +// */ +// +// try { +// // TODO: readFromMetadataFile +// Dictionary<String, Object> parameters = new Hashtable<String, Object>(); +// // TODO: mutateParameters +// Dictionary<String, Object> mutatedParameters = parameters; +// // TODO: Invoke GUI builder service, getting user-entered parameters. +// Dictionary<String, Object> userEnteredParameters = mutatedParameters; +// +// algorithm[0] = +// factory.createAlgorithm(data, userEnteredParameters, ciShellContext); +// } catch (AlgorithmCreationCanceledException e) { +// canceledException[0] = e; +// } catch (AlgorithmCreationFailedException e) { +// failedException[0] = e; +// } +// } +// }; +// +// if (shouldUseNewThread) { +// new Thread(operator).start(); +// } else { +// operator.run(); +// } +// +// return algorithm[0]; +// } +// +// public Algorithm createAlgorithm( +// final AlgorithmFactory factory, +// final Data[] data, +// final Dictionary<String, Object> parameters, +// final CIShellContext ciShellContext, +// boolean shouldUseNewThread) +// throws AlgorithmCreationCanceledException, AlgorithmCreationFailedException { +// final AlgorithmCreationCanceledException[] canceledException = +// new AlgorithmCreationCanceledException[1]; +// final AlgorithmCreationFailedException[] failedException = +// new AlgorithmCreationFailedException[1]; +// +// } +//} \ No newline at end of file Modified: trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/scheduler/SchedulerServiceImpl.java =================================================================== --- trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/scheduler/SchedulerServiceImpl.java 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.reference/src/org/cishell/reference/app/service/scheduler/SchedulerServiceImpl.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -30,7 +30,7 @@ import org.cishell.app.service.scheduler.SchedulerService; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.data.Data; -import org.cishell.reference.app.service.scheduler.AlgorithmTask.STATE; +import org.cishell.reference.app.service.scheduler.AlgorithmTask.AlgorithmState; import org.osgi.framework.ServiceReference; /** @@ -74,156 +74,150 @@ * algorithm, consider using Quartz http://www.opensymphony.com/quartz/ </li> * </ul> * - * @author Shashikant Penumarthy - * @author Bruce Herr (bh...@bh...) */ -// May 8, 2006 7:05:32 PM Shashikant Penumarthy: Initial Implementation -// July 19, 2006 10:30:00 AM Bruce Herr: Ported to new CIShell public class SchedulerServiceImpl implements SchedulerService { /** * This timer runs the algorithm scheduling task. */ - private Timer _schedulerTimer; + private Timer schedulerTimer; /** * The task which schedules algorithms to run on the _algRunningTimer. */ - private AlgSchedulerTask _algSchedulerTask; + private AlgorithmSchedulerTask algorithmSchedulerTask; /** * Convenience object for informing all the schedulers. */ - private SchedulerListenerInformer _schedulerListenerInformer; + private SchedulerListenerInformer schedulerListenerInformer; + + private boolean isShutDown = true; public SchedulerServiceImpl() { - _initialize(); + initialize(); } - public SchedulerServiceImpl(int maxSimultaneousAlgsLimit) { + public SchedulerServiceImpl(int maxSimultaneousAlgorithm) { this(); - _algSchedulerTask.setMaxSimultaneousAlgs(maxSimultaneousAlgsLimit); - _isShutDown = false; + this.algorithmSchedulerTask.setMaxSimultaneousAlgorithms(maxSimultaneousAlgorithm); + this.isShutDown = false; } - public synchronized final void setMaxSimultaneousAlgs(int max) { - _algSchedulerTask.setMaxSimultaneousAlgs(max); + public synchronized final void setMaxSimultaneousAlgorithms(int max) { + this.algorithmSchedulerTask.setMaxSimultaneousAlgorithms(max); } - private final void _initialize() { - _schedulerTimer = new Timer(true); - _schedulerListenerInformer = new SchedulerListenerInformer(); - _algSchedulerTask = new AlgSchedulerTask(_schedulerListenerInformer); - _schedulerTimer.schedule(_algSchedulerTask, 0L, 500L); + private final void initialize() { + this.schedulerTimer = new Timer(true); + this.schedulerListenerInformer = new SchedulerListenerInformer(); + this.algorithmSchedulerTask = new AlgorithmSchedulerTask(this.schedulerListenerInformer); + this.schedulerTimer.schedule(this.algorithmSchedulerTask, 0L, 500L); } public synchronized final void shutDown() { - _algSchedulerTask.cancel(); - _schedulerTimer.cancel(); - _isShutDown = true; + this.algorithmSchedulerTask.cancel(); + this.schedulerTimer.cancel(); + this.isShutDown = true; } public final boolean isEmpty() { - return _algSchedulerTask.isEmpty(); + return this.algorithmSchedulerTask.isEmpty(); } public final boolean isRunning() { - return _algSchedulerTask.isRunning(); + return this.algorithmSchedulerTask.isRunning(); } public final int numRunning() { - return _algSchedulerTask.numRunning(); + return this.algorithmSchedulerTask.numRunning(); } - private boolean _isShutDown = true; - public final boolean isShutDown() { - return _isShutDown; + return this.isShutDown; } public boolean reschedule(Algorithm algorithm, Calendar newTime) { - // Shaky method. Ideally this is done at a higher level. But still, here - // goes... - ServiceReference ref = _algSchedulerTask.getServiceReference(algorithm); - boolean status = false; + // Shaky method. Ideally this is done at a higher level. But still, here goes... + ServiceReference reference = this.algorithmSchedulerTask.getServiceReference(algorithm); + boolean canReschedule = false; + try { - STATE algState = _algSchedulerTask.getAlgorithmState(algorithm); + AlgorithmState algorithmState = + this.algorithmSchedulerTask.getAlgorithmState(algorithm); - // Cannot reschedule running algs - if (algState.equals(STATE.RUNNING)) { - status = false; + // Cannot reschedule running algorithms. + if (algorithmState.equals(AlgorithmState.RUNNING)) { + canReschedule = false; + } else if (algorithmState.equals(AlgorithmState.STOPPED)) { + this.algorithmSchedulerTask.purgeFinished(); + this.algorithmSchedulerTask.schedule(algorithm, reference, newTime); + canReschedule = true; + } else if (algorithmState.equals(AlgorithmState.NEW)) { + this.algorithmSchedulerTask.cancel(algorithm); + this.algorithmSchedulerTask.schedule(algorithm, reference, newTime); + } else { + throw new IllegalStateException("Encountered an invalid state: " + algorithmState); } - else if (algState.equals(STATE.STOPPED)) { - _algSchedulerTask.purgeFinished(); - _algSchedulerTask.schedule(algorithm, ref, newTime); - status = true; - } - else if (algState.equals(STATE.NEW)) { - _algSchedulerTask.cancel(algorithm); - _algSchedulerTask.schedule(algorithm, ref, newTime); - } - else { - throw new IllegalStateException( - "Encountered an invalid state: " + algState); - } - } catch (NoSuchElementException nsee) { - _algSchedulerTask.schedule(algorithm, ref, newTime); - status = true; + } catch (NoSuchElementException e) { + this.algorithmSchedulerTask.schedule(algorithm, reference, newTime); + canReschedule = true; } - return status; + return canReschedule; } - public void runNow(Algorithm algorithm, ServiceReference ref) { + public void runNow(Algorithm algorithm, ServiceReference reference) { // There is currently no difference between this one and - // schedule(Algorithm, ref). - schedule(algorithm, ref); + // schedule(Algorithm, reference). + schedule(algorithm, reference); } - public void schedule(Algorithm algorithm, ServiceReference ref) { - schedule(algorithm, ref, Calendar.getInstance()); + public void schedule(Algorithm algorithm, ServiceReference reference) { + schedule(algorithm, reference, Calendar.getInstance()); } - public void schedule(Algorithm algorithm, ServiceReference ref, Calendar time) { - _algSchedulerTask.schedule(algorithm, ref, time); + public void schedule(Algorithm algorithm, ServiceReference reference, Calendar time) { + this.algorithmSchedulerTask.schedule(algorithm, reference, time); } public boolean unschedule(Algorithm algorithm) { - return _algSchedulerTask.cancel(algorithm); + return this.algorithmSchedulerTask.cancel(algorithm); } public void addSchedulerListener(SchedulerListener listener) { - _schedulerListenerInformer.addSchedulerListener(listener); + this.schedulerListenerInformer.addSchedulerListener(listener); } public void removeSchedulerListener(SchedulerListener listener) { - _schedulerListenerInformer.removeSchedulerListener(listener); + this.schedulerListenerInformer.removeSchedulerListener(listener); } public synchronized void clearSchedule() { - _algSchedulerTask.cancel(); - _schedulerTimer.cancel(); + this.algorithmSchedulerTask.cancel(); + this.schedulerTimer.cancel(); - _schedulerTimer = new Timer(true); - _algSchedulerTask = new AlgSchedulerTask(_schedulerListenerInformer); - _schedulerTimer.schedule(_algSchedulerTask, 0L, 500L); + this.schedulerTimer = new Timer(true); + this.algorithmSchedulerTask = new AlgorithmSchedulerTask(this.schedulerListenerInformer); + // TODO: Make constants for these magic numbers. + this.schedulerTimer.schedule(this.algorithmSchedulerTask, 0L, 500L); - _schedulerListenerInformer.schedulerCleared(); + this.schedulerListenerInformer.schedulerCleared(); } public Algorithm[] getScheduledAlgorithms() { - return _algSchedulerTask.getScheduledAlgorithms(); + return this.algorithmSchedulerTask.getScheduledAlgorithms(); } public Calendar getScheduledTime(Algorithm algorithm) { - return _algSchedulerTask.getScheduledTime(algorithm); + return this.algorithmSchedulerTask.getScheduledTime(algorithm); } public ServiceReference getServiceReference(Algorithm algorithm) { - return _algSchedulerTask.getServiceReference(algorithm); + return this.algorithmSchedulerTask.getServiceReference(algorithm); } public void setRunning(boolean isRunning) { - _algSchedulerTask.setRunning(isRunning); - _schedulerListenerInformer.schedulerRunStateChanged(isRunning); + this.algorithmSchedulerTask.setRunning(isRunning); + this.schedulerListenerInformer.schedulerRunStateChanged(isRunning); } } @@ -238,133 +232,124 @@ * @author Team IVC */ class SchedulerListenerInformer implements SchedulerListener { + private List<SchedulerListener> schedulerListeners; - private List _schedulerListeners; - public SchedulerListenerInformer() { - _schedulerListeners = new ArrayList(); + this.schedulerListeners = new ArrayList<SchedulerListener>(); } public void addSchedulerListener(SchedulerListener listener) { - _schedulerListeners.add(listener); + this.schedulerListeners.add(listener); } public void removeSchedulerListener(SchedulerListener listener) { - _schedulerListeners.remove(listener); + this.schedulerListeners.remove(listener); } public void algorithmScheduled(Algorithm algorithm, Calendar time) { - for (Iterator iter = _schedulerListeners.iterator() ; iter.hasNext() ; ) { - SchedulerListener sl = (SchedulerListener) iter.next() ; - sl.algorithmScheduled(algorithm, time); + for (SchedulerListener schedulerListener : this.schedulerListeners) { + schedulerListener.algorithmScheduled(algorithm, time); } } public synchronized void algorithmStarted(Algorithm algorithm) { - for (Iterator iter = _schedulerListeners.iterator() ; iter.hasNext() ; ) { - SchedulerListener sl = (SchedulerListener) iter.next() ; - sl.algorithmStarted(algorithm); + for (SchedulerListener schedulerListener : this.schedulerListeners) { + schedulerListener.algorithmStarted(algorithm); } } public void algorithmError(Algorithm algorithm, Throwable error) { - for (Iterator iter = _schedulerListeners.iterator() ; iter.hasNext() ; ) { - SchedulerListener sl = (SchedulerListener) iter.next() ; - sl.algorithmError(algorithm, error); + for (SchedulerListener schedulerListener : this.schedulerListeners) { + schedulerListener.algorithmError(algorithm, error); } } public void algorithmFinished(Algorithm algorithm, Data[] createdDM) { - for (Iterator iter = _schedulerListeners.iterator() ; iter.hasNext() ; ) { - SchedulerListener sl = (SchedulerListener) iter.next() ; - sl.algorithmFinished(algorithm, createdDM); + for (SchedulerListener schedulerListener : this.schedulerListeners) { + schedulerListener.algorithmFinished(algorithm, createdDM); } } public void algorithmRescheduled(Algorithm algorithm, Calendar time) { - for (Iterator iter = _schedulerListeners.iterator() ; iter.hasNext() ; ) { - SchedulerListener sl = (SchedulerListener) iter.next() ; - sl.algorithmRescheduled(algorithm, time); + for (SchedulerListener schedulerListener : this.schedulerListeners) { + schedulerListener.algorithmRescheduled(algorithm, time); } } public void algorithmUnscheduled(Algorithm algorithm) { - for (Iterator iter = _schedulerListeners.iterator() ; iter.hasNext() ; ) { - SchedulerListener sl = (SchedulerListener) iter.next() ; - sl.algorithmUnscheduled(algorithm); + for (SchedulerListener schedulerListener : this.schedulerListeners) { + schedulerListener.algorithmUnscheduled(algorithm); } } public void schedulerCleared() { - for (Iterator iter = _schedulerListeners.iterator() ; iter.hasNext() ; ) { - SchedulerListener sl = (SchedulerListener) iter.next() ; - sl.schedulerCleared(); + for (SchedulerListener schedulerListener : this.schedulerListeners) { + schedulerListener.schedulerCleared(); } } public void schedulerRunStateChanged(boolean isRunning) { - for (Iterator iter = _schedulerListeners.iterator() ; iter.hasNext() ; ) { - SchedulerListener sl = (SchedulerListener) iter.next() ; - sl.schedulerRunStateChanged(isRunning); + for (SchedulerListener schedulerListener : this.schedulerListeners) { + schedulerListener.schedulerRunStateChanged(isRunning); } } } -class AlgSchedulerTask extends TimerTask implements SchedulerListener { +class AlgorithmSchedulerTask extends TimerTask implements SchedulerListener { + public static final int AS_MANY_SIMULTANEOUS_ALGORITHMS_AS_NEEDED = -1; + private Map<Algorithm, AlgorithmTask> tasksByAlgorithms; + private Map<Algorithm, ServiceReference> serviceReferencesByAlgorithms; + private volatile boolean isRunning = true; + private volatile int runningTaskCount = 0; + private SchedulerListener schedulerListener; + private int maxSimultaneousAlgorithms = AS_MANY_SIMULTANEOUS_ALGORITHMS_AS_NEEDED; - private Map _algMap; - private Map _algServiceMap; - private volatile boolean _running = true; - - // Default allow as many as needed - private int _maxSimultaneousAlgs = -1; - /** * Maximum number of algorithms allowed to run simultaneously. This value * can be changed at runtime without any problems. Negative values are * interpreted to mean 'no limit'. * * @param max - * The maximum number of algorithms that can be simultaneously - * run. + * The maximum number of algorithms that can be simultaneously run. */ - public synchronized final void setMaxSimultaneousAlgs(final int max) { - if (max < -1) - this._maxSimultaneousAlgs = -1; - else - this._maxSimultaneousAlgs = max; + public synchronized final void setMaxSimultaneousAlgorithms(final int max) { + if (max < -1) { + this.maxSimultaneousAlgorithms = AS_MANY_SIMULTANEOUS_ALGORITHMS_AS_NEEDED; + } else { + this.maxSimultaneousAlgorithms = max; + } } public synchronized Algorithm[] getScheduledAlgorithms() { - return (Algorithm[]) _algMap.keySet().toArray(new Algorithm[0]); + return this.tasksByAlgorithms.keySet().toArray(new Algorithm[0]); } public synchronized final boolean isEmpty() { - return _algMap.size() == 0; + return this.tasksByAlgorithms.size() == 0; } public synchronized final int numRunning() { - return _numRunning; + return this.runningTaskCount; } - private SchedulerListener _schedulerListener; - - public AlgSchedulerTask(SchedulerListener listener) { - _algMap = Collections.synchronizedMap(new HashMap()); - _algServiceMap = new HashMap(); - setSchedulerListener(listener); + public AlgorithmSchedulerTask(SchedulerListener listener) { + this.tasksByAlgorithms = + Collections.synchronizedMap(new HashMap<Algorithm, AlgorithmTask>()); + this.serviceReferencesByAlgorithms = new HashMap<Algorithm, ServiceReference>(); + this.setSchedulerListener(listener); } public synchronized final void setSchedulerListener(SchedulerListener listener) { - _schedulerListener = listener; + this.schedulerListener = listener; } public final ServiceReference getServiceReference(Algorithm algorithm) { - return (ServiceReference) _algServiceMap.get(algorithm); + return this.serviceReferencesByAlgorithms.get(algorithm); } public synchronized final Calendar getScheduledTime(Algorithm algorithm) { - AlgorithmTask task = (AlgorithmTask)_algMap.get(algorithm); + AlgorithmTask task = this.tasksByAlgorithms.get(algorithm); + if (task != null) { return task.getScheduledTime(); } else { @@ -372,10 +357,13 @@ } } - public synchronized final boolean cancel(Algorithm alg) { - AlgorithmTask task = (AlgorithmTask) this._algMap.get(alg); - if (task == null) + public synchronized final boolean cancel(Algorithm algorithm) { + AlgorithmTask task = this.tasksByAlgorithms.get(algorithm); + + if (task == null) { return false; + } + // The algorithm will run till the end and // then stop so there's no real way to cancel running algorithms. // Clients should always check the state of an algorithm before trying @@ -384,23 +372,23 @@ } public synchronized final void schedule(Algorithm alg, ServiceReference ref, Calendar time) { - AlgorithmTask task = (AlgorithmTask) this._algMap.get(alg); + AlgorithmTask task = this.tasksByAlgorithms.get(alg); // If alg already exists, do some checks... if (task != null) { - STATE state = task.getState(); + AlgorithmState state = task.getState(); // If its still running, we can't schedule it again. - if (state.equals(STATE.RUNNING)) { + if (state.equals(AlgorithmState.RUNNING)) { throw new RuntimeException( "Cannot schedule running algorithm. Check state of algorithm first."); } // If its new or waiting to run, we refuse to schedule it to force // user to explicitly // cancel and reschedule. - else if (state.equals(STATE.NEW)) { + else if (state.equals(AlgorithmState.NEW)) { throw new RuntimeException( "Algorithm is already scheduled to run. Cancel existing schedule first."); } - else if (state.equals(STATE.STOPPED)) { + else if (state.equals(AlgorithmState.STOPPED)) { // If it was stopped but not cleaned up yet, clean it up purgeFinished(); } @@ -414,21 +402,21 @@ } public synchronized final int getMaxSimultaneousAlgs() { - return this._maxSimultaneousAlgs; + return this.maxSimultaneousAlgorithms; } public synchronized final void registerAlgorithmTask(Algorithm algorithm, AlgorithmTask algorithmTask) { - this._algServiceMap.put(algorithm, algorithmTask.getServiceReference()); - this._algMap.put(algorithm, algorithmTask); + this.serviceReferencesByAlgorithms.put(algorithm, algorithmTask.getServiceReference()); + this.tasksByAlgorithms.put(algorithm, algorithmTask); } /** - * @param alg + * @param algorithm * The algorithm whose state we want to query. * @return State of the specified algorithm. */ - public synchronized final STATE getAlgorithmState(Algorithm alg) { - AlgorithmTask task = (AlgorithmTask) this._algMap.get(alg); + public synchronized final AlgorithmState getAlgorithmState(Algorithm algorithm) { + AlgorithmTask task = this.tasksByAlgorithms.get(algorithm); if (task == null) throw new NoSuchElementException("Algorithm doesn't exist."); return task.getState(); @@ -439,92 +427,95 @@ */ public synchronized final void purgeFinished() { synchronized (this) { - Iterator iter = this._algMap - .entrySet().iterator(); - while (iter.hasNext()) { - Map.Entry entry = (Map.Entry) iter.next(); - AlgorithmTask task = (AlgorithmTask) entry.getValue(); - if (task.getState() == STATE.STOPPED) { - iter.remove(); - _algServiceMap.remove(entry.getKey()); + Iterator<Map.Entry<Algorithm, AlgorithmTask>> entries = + this.tasksByAlgorithms.entrySet().iterator(); + + while (entries.hasNext()) { + Map.Entry<Algorithm, AlgorithmTask> entry = entries.next(); + AlgorithmTask task = entry.getValue(); + + if (task.getState() == AlgorithmState.STOPPED) { + entries.remove(); + this.serviceReferencesByAlgorithms.remove(entry.getKey()); } } } } - private synchronized final boolean _limitReached() { - return (_maxSimultaneousAlgs != -1) - && (_numRunning >= _maxSimultaneousAlgs); + private synchronized final boolean limitReached() { + return + (this.maxSimultaneousAlgorithms != AS_MANY_SIMULTANEOUS_ALGORITHMS_AS_NEEDED) && + (this.runningTaskCount >= this.maxSimultaneousAlgorithms); } public void setRunning(boolean isRunning) { - _running = isRunning; + this.isRunning = isRunning; } public boolean isRunning() { - return _running; + return this.isRunning; } public void run() { - if (_running) { + if (this.isRunning) { synchronized (this) { // If we are running the max allowable, wait until next turn. Date now = Calendar.getInstance().getTime(); // Iterate through algorithms. - Collection tasks = this._algMap.values(); - for (Iterator iter = tasks.iterator() ; iter.hasNext() ;) { - AlgorithmTask task = (AlgorithmTask) iter.next() ; - if (_limitReached()) + Collection<AlgorithmTask> tasks = this.tasksByAlgorithms.values(); + + for (AlgorithmTask task : tasks) { + if (limitReached()) { return; - if ((task.getState() == STATE.NEW) + } + + if ((task.getState() == AlgorithmState.NEW) && now.compareTo(task.getScheduledTime().getTime()) >= 0) { - // Run immediately + // Run immediately. task.start(); } } } } } - - private volatile int _numRunning = 0; public synchronized void algorithmScheduled(Algorithm algorithm, Calendar time) { - _schedulerListener.algorithmScheduled(algorithm, time); + this.schedulerListener.algorithmScheduled(algorithm, time); } public synchronized void algorithmStarted(Algorithm algorithm) { - _numRunning++; - _schedulerListener.algorithmStarted(algorithm); + this.runningTaskCount++; + this.schedulerListener.algorithmStarted(algorithm); } public synchronized void algorithmError(Algorithm algorithm, Throwable error) { - _numRunning--; - _schedulerListener.algorithmError(algorithm, error); + this.runningTaskCount--; + this.schedulerListener.algorithmError(algorithm, error); purgeFinished(); } public synchronized void algorithmFinished(Algorithm algorithm, Data[] createdDM) { - _numRunning--; - _schedulerListener.algorithmFinished(algorithm, createdDM); + this.runningTaskCount--; + this.schedulerListener.algorithmFinished(algorithm, createdDM); purgeFinished(); } public synchronized void algorithmRescheduled(Algorithm algorithm, Calendar time) { - _schedulerListener.algorithmRescheduled(algorithm, time); + this.schedulerListener.algorithmRescheduled(algorithm, time); } public synchronized void algorithmUnscheduled(Algorithm algorithm) { - _schedulerListener.algorithmUnscheduled(algorithm); + this.schedulerListener.algorithmUnscheduled(algorithm); } public synchronized void schedulerCleared() { - _schedulerListener.schedulerCleared(); + this.schedulerListener.schedulerCleared(); } public synchronized void schedulerRunStateChanged(boolean isRunning) { - _schedulerListener.schedulerRunStateChanged(isRunning); + this.schedulerListener.schedulerRunStateChanged(isRunning); } } @@ -542,147 +533,196 @@ // May 8, 2006 7:19:00 PM Shashikant Penumarthy: Initial implementation. //July 19, 2006 10:45:00 AM Bruce Herr: Ported to new CIShell class AlgorithmTask implements Runnable { - /** * The states in which algorithm tasks can exist. * * @author Team IVC */ - static final class STATE { - private String _name ; - public STATE(String name) { - this._name = name ; - } - public final boolean equals(Object object) { - if (! (object instanceof STATE)) - return false ; - STATE state = (STATE) object ; - return state._name.compareTo(_name) == 0; - } - /** New algorithms are in this state. */ - public static final STATE NEW = new STATE("NEW") ; - /** Running algorithms are in this state. */ - public static final STATE RUNNING = new STATE("RUNNING") ; - /** Algorithms either cancelled or finished are in this state. */ - public static final STATE STOPPED = new STATE("STOPPED") ; - /** Algorithm had an error while executing */ - public static final STATE ERROR = new STATE("ERROR"); - } + private volatile boolean isCanceled = false; + private final Algorithm algorithm; - private volatile boolean _noRun = false; + /* NOTE: TimerTask keeps its own schedule variable which can be retrieved using + * scheduledExecutionTime() method. We don't use that here. + */ + private final Calendar scheduledTime; + private final ServiceReference serviceReference; + private volatile AlgorithmState state; + // Execution status of the algorithm (i.e.) return value. + private Data[] result; + + // The exception thrown, if an algorithm had one while executing. + private Exception exceptionThrown; + + // Deliberately allow only one listener. Its not the algorithms job to do all the informing. + private SchedulerListener schedulerListener; + public synchronized final boolean cancel() { - if (_noRun) + if (this.isCanceled) { return true; - if (_state.equals(STATE.RUNNING)) + } + + if (this.state.equals(AlgorithmState.RUNNING)) { return false; - _state = STATE.STOPPED; - _noRun = true; - return _noRun; + } + + this.state = AlgorithmState.STOPPED; + this.isCanceled = true; + + return this.isCanceled; } public synchronized final void start() { - if (_noRun) + if (this.isCanceled) { return; - _setState(STATE.RUNNING); + } + + setState(AlgorithmState.RUNNING); new Thread(this).start(); } - private final Algorithm _alg; + public AlgorithmTask( + Algorithm algorithm, + ServiceReference serviceReference, + Calendar scheduledTime, + AlgorithmSchedulerTask algorithmSchedulerTask) { + this.algorithm = algorithm; + this.serviceReference = serviceReference; + this.scheduledTime = scheduledTime; + this.schedulerListener = algorithmSchedulerTask; - // NOTE: TimerTask keeps its own schedule variable which can be retrieved - // using scheduledExecutionTime() method. We don't use that here. - private final Calendar _scheduledTime; - - private final ServiceReference _ref; - - private volatile STATE _state; - - /** - * Execution status of the algorithm (i.e.) return value. - */ - private Data[] _result; - - /** - * The error, if an algorithm had one while executing - */ - private Exception _error; - - /** - * Deliberately allow only one listener. Its not the algorithms job to do - * all the informing. - */ - private SchedulerListener _schedulerListener; - - public AlgorithmTask(Algorithm alg, ServiceReference ref, Calendar scheduledTime, - //SchedulerListener listener) { - AlgSchedulerTask algSchedulerTask) { - _alg = alg; - _ref = ref; - _scheduledTime = scheduledTime; - _schedulerListener = algSchedulerTask; - algSchedulerTask.registerAlgorithmTask(alg, this); - _init(); + algorithmSchedulerTask.registerAlgorithmTask(algorithm, this); + init(); } public synchronized final Calendar getScheduledTime() { - // Do a defensive copy cuz we don't want clients changing - // the time using this reference! + /* Do a defensive copy because we don't want clients changing the time using + * this reference! + */ Calendar calendar = Calendar.getInstance(); - calendar.setTime(this._scheduledTime.getTime()); + calendar.setTime(this.scheduledTime.getTime()); + return calendar; } public synchronized final ServiceReference getServiceReference() { - return _ref; + return this.serviceReference; } - private final void _init() { - _result = null; - _setState(STATE.NEW); + private final void init() { + this.result = null; + setState(AlgorithmState.NEW); } public synchronized final Data[] getResult() { - return _result; + return this.result; } - private synchronized final void _setState(STATE state) { - this._state = state; - // Inform listeners - if (_schedulerListener != null) { - if (this._state.equals(STATE.NEW)) { - _schedulerListener.algorithmScheduled(_alg, _scheduledTime); - } - else if (this._state.equals(STATE.RUNNING)) { - _schedulerListener.algorithmStarted(_alg); - } - else if (this._state.equals(STATE.STOPPED)) { - _noRun = true; - _schedulerListener.algorithmFinished(_alg, getResult()); - } - else if (this._state.equals(STATE.ERROR)) { - _noRun = true; - _schedulerListener.algorithmError(_alg, _error); - } - else { - throw new IllegalStateException( - "Encountered illegal algorithm state: " + _state); - } + private synchronized final void setState(AlgorithmState state) { + this.state = state; + // Inform listeners. + if (this.schedulerListener != null) { + this.state.performAction( + algorithm, + this.schedulerListener, + this.scheduledTime, + getResult(), + this.exceptionThrown); + this.isCanceled = this.state.isCanceledNow(); } } - public synchronized final STATE getState() { - return this._state; + public synchronized final AlgorithmState getState() { + return this.state; } public void run() { try { - _result = _alg.execute(); + this.result = this.algorithm.execute(); } catch (Exception e) { - _error = e; - _setState(STATE.ERROR); + this.exceptionThrown = e; + setState(AlgorithmState.ERROR); } finally { - _setState(STATE.STOPPED); + setState(AlgorithmState.STOPPED); } } + + static class AlgorithmState { + /** New algorithms are in this state. */ + public static final AlgorithmState NEW = new AlgorithmState("NEW", false) { + public void performAction( + Algorithm algorithm, + SchedulerListener schedulerListener, + Calendar scheduledTime, + Data[] result, + Exception exceptionThrown) { + schedulerListener.algorithmScheduled(algorithm, scheduledTime); + } + }; + + /** Running algorithms are in this state. */ + public static final AlgorithmState RUNNING = new AlgorithmState("RUNNING", false) { + public void performAction( + Algorithm algorithm, + SchedulerListener schedulerListener, + Calendar scheduledTime, + Data[] result, + Exception exceptionThrown) { + schedulerListener.algorithmStarted(algorithm); + } + }; + /** Algorithms either cancelled or finished are in this state. */ + public static final AlgorithmState STOPPED = new AlgorithmState("STOPPED", true) { + public void performAction( + Algorithm algorithm, + SchedulerListener schedulerListener, + Calendar scheduledTime, + Data[] result, + Exception exceptionThrown) { + schedulerListener.algorithmFinished(algorithm, result); + } + }; + /** Algorithm had an exceptionThrown while executing */ + public static final AlgorithmState ERROR = new AlgorithmState("ERROR", true) { + public void performAction( + Algorithm algorithm, + SchedulerListener schedulerListener, + Calendar scheduledTime, + Data[] result, + Exception exceptionThrown) { + schedulerListener.algorithmError(algorithm, exceptionThrown); + } + }; + + private String name; + private boolean isCanceled; + + public AlgorithmState(String name, boolean isCanceled) { + this.name = name; + this.isCanceled = isCanceled; + } + + public final boolean equals(Object object) { + if (!(object instanceof AlgorithmState)) { + return false; + } + + AlgorithmState state = (AlgorithmState) object; + + return state.name.compareTo(name) == 0; + } + + public void performAction( + Algorithm algorithm, + SchedulerListener schedulerListener, + Calendar scheduledTime, + Data[] result, + Exception exceptionThrown) { + throw new IllegalStateException("Encountered illegal algorithm state: " + this); + } + + public boolean isCanceledNow() { + return this.isCanceled; + } + } } Modified: trunk/core/org.cishell.reference.services/src/org/cishell/reference/services/Activator.java =================================================================== --- trunk/core/org.cishell.reference.services/src/org/cishell/reference/services/Activator.java 2010-08-03 18:35:25 UTC (rev 1107) +++ trunk/core/org.cishell.reference.services/src/org/cishell/reference/services/Activator.java 2010-08-03 19:15:24 UTC (rev 1108) @@ -15,36 +15,46 @@ import org.osgi.framework.ServiceRegistration; public class Activator implements BundleActivator { - private ServiceRegistration conversionReg; - private ServiceRegistration schedulerReg; - private ServiceRegistration dataManagerReg; + private ServiceRegistration conversionRegistration; + private ServiceRegistration schedulerRegistration; + private ServiceRegistration dataManagerRegistration; +// private ServiceRegistration algorithmInvokerRegistration; /** * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ - public void start(BundleContext bContext) throws Exception { - CIShellContext ciContext = new LocalCIShellContext(bContext); + public void start(BundleContext bundleContext) throws Exception { + CIShellContext ciShellContext = new LocalCIShellContext(bundleContext); - DataConversionService conversionService = - new DataConversionServiceImpl(bContext, ciContext); - conversionReg = bContext.registerService( - DataConversionService.class.getName(), conversionService, new Hashtable()); + DataConversionService conversionService = + new DataConversionServiceImpl(bundleContext, ciShellContext); + this.conversionRegistration = bundleContext.registerService( + DataConversionService.class.getName(), + conversionService, + new Hashtable<String, Object>()); SchedulerService scheduler = new SchedulerServiceImpl(); - schedulerReg = bContext.registerService( - SchedulerService.class.getName(), scheduler, new Hashtable()); + this.schedulerRegistration = bundleContext.registerService( + SchedulerService.class.getName(), scheduler, new Hashtable<String, Object>()); DataManagerService dataManager = new DataManagerServiceImpl(); - dataManagerReg = bContext.registerService( - DataManagerService.class.getName(), dataManager, new Hashtable()); + this.dataManagerRegistration = bundleContext.registerService( + DataManagerService.class.getName(), dataManager, new Hashtable<String, Object>()); + +// AlgorithmInvocationService algorithmInvoker = new AlgorithmInvocationServiceImpl(); +// this.algorithmInvokerRegistration = bundleContext.registerService( +// AlgorithmInvocationService.class.getName(), +// algorithmInvoker, +// new Hashtable<String, Object>()); } /** * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ - public vo... [truncated message content] |
From: <pat...@us...> - 2010-08-03 18:35:33
|
Revision: 1107 http://cishell.svn.sourceforge.net/cishell/?rev=1107&view=rev Author: pataphil Date: 2010-08-03 18:35:25 +0000 (Tue, 03 Aug 2010) Log Message: ----------- * Changed manifest to export all packages. Modified Paths: -------------- trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF Modified: trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-03 17:23:41 UTC (rev 1106) +++ trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-03 18:35:25 UTC (rev 1107) @@ -9,4 +9,6 @@ Import-Package: com.google.common.collect, org.cishell.utilities, org.cishell.utilities.datastructure -Export-Package: org.cishell.utilities.swt +Export-Package: org.cishell.utilities.swt, + org.cishell.utilities.swt.model, + org.cishell.utilities.swt.model.datasynchronizer This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-03 17:23:48
|
Revision: 1106 http://cishell.svn.sourceforge.net/cishell/?rev=1106&view=rev Author: pataphil Date: 2010-08-03 17:23:41 +0000 (Tue, 03 Aug 2010) Log Message: ----------- * Moved SWT Utilities out to org.cishell.utilities.swt bundle. Modified Paths: -------------- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF Removed Paths: ------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/ Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-08-03 17:23:41 UTC (rev 1106) @@ -36,9 +36,4 @@ org.cishell.utilities.mutateParameter, org.cishell.utilities.mutateParameter.defaultvalue, org.cishell.utilities.mutateParameter.dropdown, - org.cishell.utilities.osgi.logging, - org.cishell.utilities.swt, - org.cishell.utilities.swt.model, - org.cishell.utilities.swt.model.datasynchronizer -Require-Bundle: org.eclipse.ui;resolution:=optional, - org.eclipse.core.runtime;resolution:=optional + org.cishell.utilities.osgi.logging Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,243 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.ScrolledComposite; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; - -/** - * This is meant to be subclassed. - */ -public class ExpandableComponentWidget<T> extends Composite { - public static final int COLUMN_AREA_LAYOUT_VERTICAL_SPACING = 1; - public static final int VERTICAL_SCROLL_INCREMENT = 50; - - private ScrolledComponentFactory<T> componentFactory; - private Composite headerArea; - private ScrolledComposite scrollingArea; - private GridContainer scrolledAreaGrid; - private Composite footerArea; - private List<T> components = new ArrayList<T>(); - private int uniqueComponentCount = 0; - private Collection<Label> columnLabels; - - public ExpandableComponentWidget( - Composite parent, ScrolledComponentFactory<T> componentFactory) { - super(parent, SWT.NONE); - this.componentFactory = componentFactory; - - setLayout(createLayout()); - this.headerArea = createHeaderArea(); - this.scrollingArea = createScrollingArea(); - this.footerArea = createFooterArea(); - this.scrolledAreaGrid = createScrolledAreaGrid(this.scrollingArea); - - this.scrollingArea.setExpandHorizontal(true); - this.scrollingArea.setExpandVertical(true); - this.scrollingArea.setAlwaysShowScrollBars(true); - fixSize(); - this.scrollingArea.setContent(this.scrolledAreaGrid.getActualParent()); - this.scrollingArea.getVerticalBar().setPageIncrement(VERTICAL_SCROLL_INCREMENT); - this.columnLabels = createColumnLabels(this.scrolledAreaGrid.getActualParent(), SWT.NONE); - } - - public Composite getHeaderArea() { - return this.headerArea; - } - - public Composite getFooterArea() { - return this.footerArea; - } - - public List<T> getComponents() { - return Collections.unmodifiableList(this.components); - } - - public int getColumnCount() { - return 1; - } - - public T addComponent(int style, Map<String, Object> arguments) { - // TODO: Fix this terrible hack? - if (this.components.size() == 0) { - for (Label columnLabel : this.columnLabels) { - columnLabel.setVisible(true); - } - } - - final int componentCount = this.components.size(); - T component = this.componentFactory.constructWidget( - this, this.scrolledAreaGrid, style, arguments, componentCount, this.uniqueComponentCount); - this.uniqueComponentCount++; - - fixSize(); - - this.components.add(component); - - return component; - } - - public void removeComponent(int index) { - this.scrolledAreaGrid.removeRow(index); - this.components.remove(index); - fixSize(); - - for (int ii = 0; ii < this.components.size(); ii++) { - this.componentFactory.reindexComponent(this.components.get(ii), ii); - } - - // TODO: Fix this terrible hack? - if (this.components.size() == 0) { - for (Label columnLabel : this.columnLabels) { - columnLabel.setVisible(false); - } - } - } - - public Collection<Label> createColumnLabels(Composite parent, int style) { - List<Label> columnLabels = new ArrayList<Label>(); - - for (String columnLabelText : createColumnLabelTexts()) { - Label columnLabel = new Label(parent, style); - columnLabel.setLayoutData(createColumnLabelLayoutData()); - columnLabel.setText(columnLabelText); - columnLabels.add(columnLabel); - } - - return columnLabels; - } - - public Collection<String> createColumnLabelTexts() { - List<String> columnLabelTexts = new ArrayList<String>(); - - for (int ii = 0; ii < getColumnCount(); ii++) { - columnLabelTexts.add("Column " + ii); - } - - return columnLabelTexts; - } - - private void fixSize() { - Composite scrolledArea = this.scrolledAreaGrid.getActualParent(); - this.scrollingArea.setMinSize(scrolledArea.computeSize(SWT.DEFAULT, SWT.DEFAULT)); - scrolledArea.pack(); - } - - protected Composite createHeaderArea() { - Composite headerArea = new Composite(this, SWT.NONE); - headerArea.setLayoutData(createHeaderAreaLayoutData()); - headerArea.setLayout(createHeaderLayout()); - - return headerArea; - } - - protected GridData createHeaderAreaLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); - - return layoutData; - } - - protected GridLayout createHeaderLayout() { - GridLayout layout = new GridLayout(1, false); - GUIBuilderUtilities.clearMargins(layout); - GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } - - protected ScrolledComposite createScrollingArea() { - ScrolledComposite scrollingArea = - new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL); - scrollingArea.setLayoutData(createScrollingAreaLayoutData()); - scrollingArea.setLayout(createScrollingLayout()); - - return scrollingArea; - } - - protected GridData createScrollingAreaLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); - - return layoutData; - } - - private GridLayout createScrollingLayout() { - GridLayout layout = new GridLayout(1, true); - GUIBuilderUtilities.clearMargins(layout); - GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } - - protected Composite createFooterArea() { - Composite footerArea = new Composite(this, SWT.BORDER); - footerArea.setLayoutData(createFooterAreaLayoutData()); - footerArea.setLayout(createFooterLayout()); - - return footerArea; - } - - protected GridData createFooterAreaLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); - - return layoutData; - } - - protected GridLayout createFooterLayout() { - GridLayout layout = new GridLayout(1, false); - GUIBuilderUtilities.clearMargins(layout); - GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } - - private GridContainer createScrolledAreaGrid(Composite parent) { - Composite columnArea = new Composite(parent, SWT.NONE); - columnArea.setLayoutData(createScrolledAreaLayoutData()); - final int columnCount = getColumnCount(); - columnArea.setLayout(createScrolledAreaLayout(columnCount)); - - return new GridContainer(columnArea, columnCount); - } - - protected GridData createScrolledAreaLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); - - return layoutData; - } - - protected GridLayout createScrolledAreaLayout(int columnCount) { - GridLayout layout = new GridLayout(columnCount, false); -// GUIBuilderUtilities.clearMargins(layout); -// GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } - - protected GridData createColumnLabelLayoutData() { - GridData layoutData = new GridData(SWT.CENTER, SWT.CENTER, false, false); - - return layoutData; - } - - protected GridData createComponentLayoutData() { - GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); - - return layoutData; - } - - private static GridLayout createLayout() { - GridLayout layout = new GridLayout(1, true); - GUIBuilderUtilities.clearMargins(layout); - GUIBuilderUtilities.clearSpacing(layout); - - return layout; - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,52 +0,0 @@ -package org.cishell.utilities.swt; - -import java.io.File; - -import org.cishell.utilities.StringUtilities; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; - -public class FileSaveAs { - public static final String DEFAULT_WINDOW_TITLE = "Save As"; - public static final String CONFIRMATION_DIALOG_FORMAT = - "%s already exists.\nDo you want to replace it?"; -// public static final String YES_BUTTON_LABEL = "Yes"; -// public static final String NO_BUTTON_LABEL = "No"; -// public static final String[] BUTTON_LABELS = { YES_BUTTON_LABEL, NO_BUTTON_LABEL }; - - public static String saveFileAs(Shell parent) { - FileDialog saveDialog = new FileDialog(parent); - saveDialog.setText(DEFAULT_WINDOW_TITLE); - - return saveFileAs(saveDialog); - } - - public static String saveFileAs(Shell parent, int style) { - FileDialog saveDialog = new FileDialog(parent, style); - saveDialog.setText(DEFAULT_WINDOW_TITLE); - - return saveFileAs(saveDialog); - } - - public static String saveFileAs(FileDialog saveDialog) { - while (true) { - String selectedFilePath = saveDialog.open(); - - if (StringUtilities.isNull_Empty_OrWhitespace(selectedFilePath)) { - return null; - } else { - if (new File(selectedFilePath).exists()) { - if (MessageDialog.openConfirm( - saveDialog.getParent(), - saveDialog.getText(), - String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath))) { - return selectedFilePath; - } - } else { - return selectedFilePath; - } - } - } - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,124 +0,0 @@ -package org.cishell.utilities.swt; - -import org.cishell.utilities.datastructure.ObjectContainer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ShellEvent; -import org.eclipse.swt.events.ShellListener; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Shell; - -public class GUIBuilderUtilities { - public static Display createDisplay() { - return new Display(); - } - - public static Shell createShell( - Display display, - String windowTitle, - int windowWidth, - int windowHeight, - int columnCount, - boolean clearSpacing) { - Shell shell = new Shell(display, SWT.CLOSE | SWT.MIN | SWT.TITLE); - shell.setText(windowTitle); - shell.setSize(windowWidth, windowHeight); - shell.setLayout(createShellLayout(columnCount, clearSpacing)); - - return shell; - } - - public static GridLayout createShellLayout(int columnCount, boolean clearSpacing) { - GridLayout layout = new GridLayout(columnCount, true); - - if (clearSpacing) { - clearSpacing(layout); - } - - return layout; - } - - public static void openShell( - Shell shell, int windowHeight, boolean useWindowHeightToSizeShell) { -// if (useWindowHeightToSizeShell) { -// /* (So far, we've created the shell at the maximum possible size we'll allow -// * (according to windowHeight). This line shrinks the shell to be a more fitting size -// * if the actual contents (i.e. our (number of) columns) are smaller than the maximum -// * size we set.) -// */ -// Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); -// shell.setMinimumSize(shellSize.x, Math.min(windowHeight, shellSize.y)); -// } - - shell.pack(); - shell.open(); - - if (useWindowHeightToSizeShell) { - Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); - shell.setSize(shell.getSize().x, Math.min(windowHeight, shellSize.y)); - } - } - - public static void swtLoop(Display display, Shell shell) { - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - display.dispose(); - } - - public static void clearMargins(GridLayout layout) { - layout.marginTop = layout.marginBottom = layout.marginHeight = 0; - layout.marginLeft = layout.marginRight = layout.marginWidth = 0; - } - - public static void clearSpacing(GridLayout layout) { - layout.horizontalSpacing = layout.verticalSpacing = 0; - } - - public static void setCancelable( - final Shell shell, final ObjectContainer<GUICanceledException> exceptionThrown) { - shell.addListener(SWT.Traverse, new Listener() { - public void handleEvent(Event event) { - switch (event.detail) { - case SWT.TRAVERSE_ESCAPE: - shell.close(); - event.detail = SWT.TRAVERSE_NONE; - event.doit = false; - -// if (exceptionThrown != null) { -// String exceptionMessage = "Canceled by user."; -// exceptionThrown.object = new GUICanceledException(exceptionMessage); -// } - - break; - } - } - }); - shell.addShellListener(new ShellListener() { - public void shellActivated(ShellEvent event) { - } - - public void shellClosed(ShellEvent event) { - if (exceptionThrown != null) { - String exceptionMessage = "Canceled by user."; - exceptionThrown.object = new GUICanceledException(exceptionMessage); - } - } - - public void shellDeactivated(ShellEvent event) { - } - - public void shellDeiconified(ShellEvent event) { - } - - public void shellIconified(ShellEvent event) { - } - }); - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,21 +0,0 @@ -package org.cishell.utilities.swt; - -public class GUICanceledException extends Exception { - private static final long serialVersionUID = 1L; - - public GUICanceledException() { - super(); - } - - public GUICanceledException(String arg0) { - super(arg0); - } - - public GUICanceledException(Throwable arg0) { - super(arg0); - } - - public GUICanceledException(String arg0, Throwable arg1) { - super(arg0, arg1); - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,92 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Widget; - -public class GridContainer { - private Composite actualParent; - private int columnCount; - private List<GridRow> rows = new ArrayList<GridRow>(); - - public GridContainer(Composite actualParent, int columnCount) { - this.actualParent = actualParent; - this.columnCount = columnCount; - } - - public Composite getActualParent() { - return this.actualParent; - } - - public int getColumnCount() { - return this.columnCount; - } - - public int getRowCount() { - return this.rows.size(); - } - - public GridRow addComponent(Widget component) { - GridRow lastRow = getOrCreateLastUsableRow(); - lastRow.addComponent(component); - - return lastRow; - } - - public void removeRow(int rowIndex) { - this.rows.get(rowIndex).dispose(); - this.rows.remove(rowIndex); - } - - private GridRow getOrCreateLastUsableRow() { - final int rowCount = getRowCount(); - - if (rowCount == 0) { - return addNewRow(); - } else { - GridRow lastRow = this.rows.get(rowCount - 1); - - if (lastRow.componentCount < getColumnCount()) { - return lastRow; - } else { - return addNewRow(); - } - } - } - - private GridRow addNewRow() { - GridRow row = new GridRow(getRowCount()); - this.rows.add(row); - - return row; - } - - public class GridRow { - private int rowIndex; - private int componentCount = 0; - private Collection<Widget> components = - new ArrayList<Widget>(GridContainer.this.columnCount); - - private GridRow(int rowIndex) { - this.rowIndex = rowIndex; - } - - public int getRowIndex() { - return this.rowIndex; - } - - private void addComponent(Widget component) { - this.components.add(component); - this.componentCount++; - } - - private void dispose() { - for (Widget component : this.components) { - component.dispose(); - } - } - } -} Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,123 +0,0 @@ -package org.cishell.utilities.swt; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; - -public class SWTUtilities { - /* - * Append the given string to the console with the given color, this will do the job of - * checking for URLs within the string and registering the proper listeners on them as well. - */ - public static void appendStringWithURL( - StyledText textField, - URLClickedListener urlListener, - URLMouseCursorListener urlCursorListener, - String message, - Color normalColor, - Color urlColor) { - - //find a URL in the message - - int index = message.indexOf("http://"); - if (index == -1) { - index = message.indexOf("https://"); - } - if (index == -1) { - index = message.indexOf("www."); - } - - if (index > -1) { - String url = message.substring(index); - if (url.indexOf(") ") > -1) { - url = url.substring(0, url.indexOf(") ")); - } - else if (url.indexOf(" ") > -1) { - url = url.substring(0, url.indexOf(" ")); - if (url.trim().endsWith(".") ){ - url=url.substring(0, url.length()-1); - } - } - if (url.endsWith(".\n") || url.endsWith(".\t")){ - url=url.substring(0, url.length()-2); - } - if (url.indexOf("\n") > -1) { - url = url.substring(0, url.indexOf("\n")); - } - if (url.indexOf("\t") > -1) { - url = url.substring(0, url.indexOf("\n")); - } - - - syncedStyledPrint(textField, message.substring(0, index), normalColor, SWT.NORMAL); - urlListener.addURL(textField.getText().length(), url); - urlCursorListener.addURL(textField.getText().length(), url); - syncedStyledPrint(textField, url, urlColor, SWT.BOLD); - appendStringWithURL( - textField, - urlListener, - urlCursorListener, - message.substring(index + url.length()), - normalColor,urlColor); - } else { - syncedStyledPrint(textField, message, normalColor, SWT.NORMAL); - } - } - - /* - * Helper to actually format the string with a style range and - * append it to the StyledText control. - */ - - public static void syncedStyledPrint( - final StyledText textField, final String message, final Color color, final int style) { - Display.getDefault().syncExec(new Runnable() { - public void run(){ - styledPrint(textField, message, color, style); - } - }); - } - - public static void styledPrint(StyledText textField, String message, Color color, int style) { - if (!textField.isDisposed()) { - textField.append(message); - - StyleRange styleRange = new StyleRange(); - styleRange.start = textField.getText().length() - message.length(); - styleRange.length = message.length(); - styleRange.foreground = color; - styleRange.fontStyle = style; - textField.setStyleRange(styleRange); - - // This makes it autoscroll. - textField.setTopIndex(textField.getLineCount()); - } - } - - public static void printURL( - Composite parent, - StyledText textField, - String url, - String displayURL, - Color color, - int style) { - URLClickedListener urlClickedListener = new URLClickedListener(textField); - URLMouseCursorListener urlCursorListener = - new URLMouseCursorListener(parent, textField); - textField.addMouseListener(urlClickedListener); - textField.addMouseMoveListener(urlCursorListener); - - urlClickedListener.addURL( - textField.getText().length(), url, displayURL); - urlCursorListener.addURL( - textField.getText().length(), url, displayURL); - SWTUtilities.styledPrint( - textField, - displayURL, - color, - style); - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,15 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.Map; - -public interface ScrolledComponentFactory<T> { - public T constructWidget( - ExpandableComponentWidget<T> componentWidget, - GridContainer scrolledAreaGrid, - int style, - Map<String, Object> arguments, - int index, - int uniqueIndex); - - public void reindexComponent(T component, int newIndex); -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,70 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.MouseAdapter; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.program.Program; - -/* - * Listens for clicks on urls and launches a browser. - */ -public class URLClickedListener extends MouseAdapter { - private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>(); - private Map<String, String> urlsToDisplayURLs = new HashMap<String, String>(); - private StyledText textField; - - public URLClickedListener(StyledText textField) { - super(); - this.textField = textField; - } - - public void addURL(int offset, String url) { - addURL(offset, url, url); - } - - public void addURL(int offset, String url, String displayURL) { - this.offsetsToURLs.put(offset, url); - this.urlsToDisplayURLs.put(url, displayURL); - } - - public void mouseDown(MouseEvent event) { - if (event.button != 1) { - return; - } - - int clickedPosition = determineClickedPosition(event); - - if (clickedPosition < 0) { - return; - } - - for (Integer offset : this.offsetsToURLs.keySet().toArray(new Integer[0])) { - String url = this.offsetsToURLs.get(offset); - String displayURL = this.urlsToDisplayURLs.get(url); - - if ((displayURL != null) && - (clickedPosition >= offset.intValue()) && - (clickedPosition <= (offset.intValue() + displayURL.length()))) { - try { - Program.launch(url); - } catch (Exception e) { - } - } - } - } - - private int determineClickedPosition(MouseEvent event) { - int clickedPosition = -1; - - try { - clickedPosition = this.textField.getOffsetAtLocation(new Point(event.x, event.y)); - } catch (IllegalArgumentException ex) { - } - - return clickedPosition; - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,79 +0,0 @@ -package org.cishell.utilities.swt; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseMoveListener; -import org.eclipse.swt.graphics.Cursor; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Composite; - -/* - * Monitors the mouse and changes the cursor when it is over a URL. - */ -public class URLMouseCursorListener implements MouseMoveListener { - private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>(); - private Map<String, String> urlsToDisplayURLs = new HashMap<String, String>(); - private Composite parent; - private StyledText textField; - - public URLMouseCursorListener(Composite parent, StyledText textField) { - this.parent = parent; - this.textField = textField; - } - - public void addURL(int offset, String url) { - addURL(offset, url, url); - } - - public void addURL(int offset, String url, String displayURL) { - this.offsetsToURLs.put(new Integer(offset), url); - this.urlsToDisplayURLs.put(url, displayURL); - } - - public void mouseMove(MouseEvent event) { - int urlOffsetOfMousePosition = determineURLOffsetOfMousePosition(event); - Integer[] urlOffsets = this.offsetsToURLs.keySet().toArray(new Integer[0]); - boolean mouseIsOverURL = determineIfMouseIsHoveringOverURL(urlOffsetOfMousePosition, urlOffsets); - Cursor cursor = new Cursor(parent.getDisplay(), determineMouseCursor(mouseIsOverURL)); - textField.setCursor(cursor); - } - - private int determineURLOffsetOfMousePosition(MouseEvent event) { - try { - return textField.getOffsetAtLocation(new Point(event.x, event.y)); - } catch (IllegalArgumentException e) { - Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW); - textField.setCursor(cursor); - } - - return -1; - } - - private boolean determineIfMouseIsHoveringOverURL( - int urlOffsetOfMousePosition, Integer[] urlOffsets) { - for (Integer urlOffset : urlOffsets) { - String url = this.offsetsToURLs.get(urlOffset); - - if ((urlOffset != null) && - (url != null) && - (urlOffsetOfMousePosition >= urlOffset.intValue()) && - (urlOffsetOfMousePosition <= (urlOffset.intValue() + url.length()))) { - return true; - } - } - - return false; - } - - private int determineMouseCursor(boolean mouseIsOverURL) { - if (mouseIsOverURL) { - return SWT.CURSOR_HAND; - } else { - return SWT.CURSOR_ARROW; - } - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,190 +0,0 @@ -package org.cishell.utilities.swt.model; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.cishell.utilities.swt.model.datasynchronizer.CheckBoxDataSynchronizer; -import org.cishell.utilities.swt.model.datasynchronizer.DropDownDataSynchronizer; -import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; -import org.cishell.utilities.swt.model.datasynchronizer.SingleListSelectionDataSynchronizer; -import org.cishell.utilities.swt.model.datasynchronizer.TextDataSynchronizer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.List; -import org.eclipse.swt.widgets.Text; -import org.eclipse.swt.widgets.Widget; - -public class GUIModel { - private Map<String, GUIModelGroup> groups = new HashMap<String, GUIModelGroup>(); - - public GUIModel() { - } - - public Collection<String> getGroupNames() { - return this.groups.keySet(); - } - - public Collection<GUIModelGroup> getGroups() { - return this.groups.values(); - } - - public GUIModelGroup getGroup(String name) { - if (!this.groups.containsKey(name)) { - GUIModelGroup newGroup = new GUIModelGroup(name); - this.groups.put(name, newGroup); - - return newGroup; - } else { - return this.groups.get(name); - } - } - - public GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> addCheckBox( - String groupName, String name, boolean on, Composite parent, int style) { - Button checkBox = new Button(parent, style | SWT.CHECK); - CheckBoxDataSynchronizer dataSynchronizer = new CheckBoxDataSynchronizer(checkBox, on); - GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> field = - new GUIModelField<Boolean, Button, CheckBoxDataSynchronizer>( - name, on, checkBox, dataSynchronizer); - addField(groupName, field); - - return field; - } - - public GUIModelField<String, Combo, DropDownDataSynchronizer> addDropDown( - String groupName, - String name, - int selectedIndex, - Collection<String> unorderedOptionLabels, - Map<String, String> optionValuesByLabels, - Composite parent, - int style) { - java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels); - Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN); - DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer( - dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels); - GUIModelField<String, Combo, DropDownDataSynchronizer> field = - new GUIModelField<String, Combo, DropDownDataSynchronizer>( - name, - optionValuesByLabels.get(orderedOptionLabels.get(selectedIndex)), - dropDown, - dataSynchronizer); - addField(groupName, field); - - return field; - } - - // TODO: addMultiSelectionDropDown - - // TODO: Test this out. - // TODO: Make it so the build works with this stuff. -// public GUIModelField< -// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> -// addDate(String name, org.joda.time.DateTime date, Composite parent, int style) { -// org.eclipse.swt.widgets.DateTime dateSelector = -// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.DATE); -// DateDataSynchronizer dataSynchronizer = new DateDataSynchronizer(dateSelector, date); -// GUIModelField< -// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> field = -// new GUIModelField< -// org.joda.time.DateTime, -// org.eclipse.swt.widgets.DateTime, -// DateDataSynchronizer>( -// name, date, dateSelector, dataSynchronizer); -// addField(field); -// -// return field; -// } - - // TODO: Test this out. -// public GUIModelField< -// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> -// addTime(String name, org.joda.time.DateTime time, Composite parent, int style) { -// org.eclipse.swt.widgets.DateTime timeSelector = -// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.TIME); -// TimeDataSynchronizer dataSynchronizer = new TimeDataSynchronizer(timeSelector, time); -// GUIModelField< -// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> field = -// new GUIModelField< -// org.joda.time.DateTime, -// org.eclipse.swt.widgets.DateTime, -// TimeDataSynchronizer>( -// name, time, timeSelector, dataSynchronizer); -// addField(field); -// -// return field; -// } - - // TODO: addCalendar - - // TODO: Test this out. - public GUIModelField<String, List, SingleListSelectionDataSynchronizer> addList( - String groupName, - String name, - int selectedIndex, - Collection<String> unorderedOptionLabels, - Map<String, String> optionValuesByLabels, - Composite parent, - int style) { - java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels); - List list = new List(parent, style | SWT.SINGLE); - SingleListSelectionDataSynchronizer dataSynchronizer = - new SingleListSelectionDataSynchronizer( - list, selectedIndex, orderedOptionLabels, optionValuesByLabels); - GUIModelField<String, List, SingleListSelectionDataSynchronizer> field = - new GUIModelField<String, List, SingleListSelectionDataSynchronizer>( - name, list.getItem(selectedIndex), list, dataSynchronizer); - addField(groupName, field); - - return field; - } - - // TODO: addMultiSelectionList - // TODO: addProgressBar - // TODO: addSash? - // TODO: addSlider - // TODO: addScale - // TODO: addSpinner - // TODO: addStyledText - - public GUIModelField<String, Text, TextDataSynchronizer> addText( - String groupName, - String name, - String value, - boolean isMultiLined, - Composite parent, - int style) { - if (isMultiLined) { - style = style | SWT.MULTI; - } else { - style = style | SWT.SINGLE; - } - - Text text = new Text(parent, style); - TextDataSynchronizer dataSynchronizer = new TextDataSynchronizer(text, value); - GUIModelField<String, Text, TextDataSynchronizer> field = - new GUIModelField<String, Text, TextDataSynchronizer>( - name, value, text, dataSynchronizer); - addField(groupName, field); - - return field; - } - - public<T> void addField( - String groupName, - GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { - GUIModelGroup group = getGroup(groupName); - group.addField(field); - } - - public<T> void removeField( - GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { - for (GUIModelGroup group : this.groups.values()) { - group.removeField(field); - } - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,65 +0,0 @@ -package org.cishell.utilities.swt.model; - -import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; -import org.eclipse.swt.widgets.Widget; - -public class GUIModelField<T, U extends Widget, V extends ModelDataSynchronizer<T>> { - private String name; - private T defaultValue; - private T previousValue; - private T value; - private U widget; - private V dataSynchronizer; - - public GUIModelField( - String name, - T defaultValue, - U widget, - V dataSynchronizer) { - this.name = name; - this.defaultValue = defaultValue; - this.value = this.defaultValue; - this.widget = widget; - this.dataSynchronizer = dataSynchronizer; - - this.widget.addListener(this.dataSynchronizer.swtUpdateListenerCode(), new Listener() { - public void handleEvent(Event event) { - if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) { - GUIModelField.this.previousValue = GUIModelField.this.value; - GUIModelField.this.value = - GUIModelField.this.dataSynchronizer.synchronizeFromGUI(); - } - } - }); - } - - public String getName() { - return this.name; - } - - public T getPreviousValue() { - return this.previousValue; - } - - public T getValue() { - return this.value; - } - - public U getWidget() { - return this.widget; - } - - public V getDataSynchronizer() { - return this.dataSynchronizer; - } - - public void setValue(T value) { - this.value = this.dataSynchronizer.synchronizeToGUI(value); - } - - public void reset() { - this.value = this.dataSynchronizer.reset(this.defaultValue); - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,57 +0,0 @@ -package org.cishell.utilities.swt.model; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; -import org.eclipse.swt.widgets.Widget; - -public class GUIModelGroup { - private String name; - private Map<String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> - inputFieldsByName = new HashMap< - String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>(); - - public GUIModelGroup(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - public Collection<String> getFieldNames() { - return this.inputFieldsByName.keySet(); - } - - public Collection< - GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> getFields() { - return this.inputFieldsByName.values(); - } - - public GUIModelField< - ?, ? extends Widget, ? extends ModelDataSynchronizer<?>> getField(String name) { - return this.inputFieldsByName.get(name); - } - - public<T> void addField( - GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { - String fieldName = field.getName(); - - if (this.inputFieldsByName.containsKey(fieldName)) { - String exceptionMessage = - "A field with the name \"" + fieldName + "\" already exists. Unable to continue."; - throw new ModelFieldException(exceptionMessage); - } - - this.inputFieldsByName.put(fieldName, field); - } - - public<T> void removeField( - GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { - if (this.inputFieldsByName.containsValue(field)) { - this.inputFieldsByName.remove(field.getName()); - } - } -} \ No newline at end of file Deleted: trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java 2010-08-03 17:21:00 UTC (rev 1105) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java 2010-08-03 17:23:41 UTC (rev 1106) @@ -1,21 +0,0 @@ -package org.cishell.utilities.swt.model; - -public class ModelFieldException extends RuntimeException { - private static final long serialVersionUID = 1L; - - public ModelFieldException() { - super(); - } - - public ModelFieldException(String arg0) { - super(arg0); - } - - public ModelFieldException(Throwable arg0) { - super(arg0); - } - - public ModelFieldException(String arg0, Throwable arg1) { - super(arg0, arg1); - } -} \ 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: <pat...@us...> - 2010-08-03 17:21:08
|
Revision: 1105 http://cishell.svn.sourceforge.net/cishell/?rev=1105&view=rev Author: pataphil Date: 2010-08-03 17:21:00 +0000 (Tue, 03 Aug 2010) Log Message: ----------- * Moved SWT Utilities out of org.cishell.utilities bundle. Modified Paths: -------------- trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF Added Paths: ----------- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java Modified: trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-03 17:18:39 UTC (rev 1104) +++ trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-03 17:21:00 UTC (rev 1105) @@ -4,3 +4,9 @@ Bundle-SymbolicName: org.cishell.utilities.swt Bundle-Version: 1.0.0 Bundle-RequiredExecutionEnvironment: J2SE-1.5 +Require-Bundle: org.eclipse.ui;bundle-version="3.4.1", + org.eclipse.core.runtime;bundle-version="3.4.0" +Import-Package: com.google.common.collect, + org.cishell.utilities, + org.cishell.utilities.datastructure +Export-Package: org.cishell.utilities.swt Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ExpandableComponentWidget.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,243 @@ +package org.cishell.utilities.swt; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +/** + * This is meant to be subclassed. + */ +public class ExpandableComponentWidget<T> extends Composite { + public static final int COLUMN_AREA_LAYOUT_VERTICAL_SPACING = 1; + public static final int VERTICAL_SCROLL_INCREMENT = 50; + + private ScrolledComponentFactory<T> componentFactory; + private Composite headerArea; + private ScrolledComposite scrollingArea; + private GridContainer scrolledAreaGrid; + private Composite footerArea; + private List<T> components = new ArrayList<T>(); + private int uniqueComponentCount = 0; + private Collection<Label> columnLabels; + + public ExpandableComponentWidget( + Composite parent, ScrolledComponentFactory<T> componentFactory) { + super(parent, SWT.NONE); + this.componentFactory = componentFactory; + + setLayout(createLayout()); + this.headerArea = createHeaderArea(); + this.scrollingArea = createScrollingArea(); + this.footerArea = createFooterArea(); + this.scrolledAreaGrid = createScrolledAreaGrid(this.scrollingArea); + + this.scrollingArea.setExpandHorizontal(true); + this.scrollingArea.setExpandVertical(true); + this.scrollingArea.setAlwaysShowScrollBars(true); + fixSize(); + this.scrollingArea.setContent(this.scrolledAreaGrid.getActualParent()); + this.scrollingArea.getVerticalBar().setPageIncrement(VERTICAL_SCROLL_INCREMENT); + this.columnLabels = createColumnLabels(this.scrolledAreaGrid.getActualParent(), SWT.NONE); + } + + public Composite getHeaderArea() { + return this.headerArea; + } + + public Composite getFooterArea() { + return this.footerArea; + } + + public List<T> getComponents() { + return Collections.unmodifiableList(this.components); + } + + public int getColumnCount() { + return 1; + } + + public T addComponent(int style, Map<String, Object> arguments) { + // TODO: Fix this terrible hack? + if (this.components.size() == 0) { + for (Label columnLabel : this.columnLabels) { + columnLabel.setVisible(true); + } + } + + final int componentCount = this.components.size(); + T component = this.componentFactory.constructWidget( + this, this.scrolledAreaGrid, style, arguments, componentCount, this.uniqueComponentCount); + this.uniqueComponentCount++; + + fixSize(); + + this.components.add(component); + + return component; + } + + public void removeComponent(int index) { + this.scrolledAreaGrid.removeRow(index); + this.components.remove(index); + fixSize(); + + for (int ii = 0; ii < this.components.size(); ii++) { + this.componentFactory.reindexComponent(this.components.get(ii), ii); + } + + // TODO: Fix this terrible hack? + if (this.components.size() == 0) { + for (Label columnLabel : this.columnLabels) { + columnLabel.setVisible(false); + } + } + } + + public Collection<Label> createColumnLabels(Composite parent, int style) { + List<Label> columnLabels = new ArrayList<Label>(); + + for (String columnLabelText : createColumnLabelTexts()) { + Label columnLabel = new Label(parent, style); + columnLabel.setLayoutData(createColumnLabelLayoutData()); + columnLabel.setText(columnLabelText); + columnLabels.add(columnLabel); + } + + return columnLabels; + } + + public Collection<String> createColumnLabelTexts() { + List<String> columnLabelTexts = new ArrayList<String>(); + + for (int ii = 0; ii < getColumnCount(); ii++) { + columnLabelTexts.add("Column " + ii); + } + + return columnLabelTexts; + } + + private void fixSize() { + Composite scrolledArea = this.scrolledAreaGrid.getActualParent(); + this.scrollingArea.setMinSize(scrolledArea.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + scrolledArea.pack(); + } + + protected Composite createHeaderArea() { + Composite headerArea = new Composite(this, SWT.NONE); + headerArea.setLayoutData(createHeaderAreaLayoutData()); + headerArea.setLayout(createHeaderLayout()); + + return headerArea; + } + + protected GridData createHeaderAreaLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); + + return layoutData; + } + + protected GridLayout createHeaderLayout() { + GridLayout layout = new GridLayout(1, false); + GUIBuilderUtilities.clearMargins(layout); + GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } + + protected ScrolledComposite createScrollingArea() { + ScrolledComposite scrollingArea = + new ScrolledComposite(this, SWT.BORDER | SWT.V_SCROLL); + scrollingArea.setLayoutData(createScrollingAreaLayoutData()); + scrollingArea.setLayout(createScrollingLayout()); + + return scrollingArea; + } + + protected GridData createScrollingAreaLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + + return layoutData; + } + + private GridLayout createScrollingLayout() { + GridLayout layout = new GridLayout(1, true); + GUIBuilderUtilities.clearMargins(layout); + GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } + + protected Composite createFooterArea() { + Composite footerArea = new Composite(this, SWT.BORDER); + footerArea.setLayoutData(createFooterAreaLayoutData()); + footerArea.setLayout(createFooterLayout()); + + return footerArea; + } + + protected GridData createFooterAreaLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); + + return layoutData; + } + + protected GridLayout createFooterLayout() { + GridLayout layout = new GridLayout(1, false); + GUIBuilderUtilities.clearMargins(layout); + GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } + + private GridContainer createScrolledAreaGrid(Composite parent) { + Composite columnArea = new Composite(parent, SWT.NONE); + columnArea.setLayoutData(createScrolledAreaLayoutData()); + final int columnCount = getColumnCount(); + columnArea.setLayout(createScrolledAreaLayout(columnCount)); + + return new GridContainer(columnArea, columnCount); + } + + protected GridData createScrolledAreaLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + + return layoutData; + } + + protected GridLayout createScrolledAreaLayout(int columnCount) { + GridLayout layout = new GridLayout(columnCount, false); +// GUIBuilderUtilities.clearMargins(layout); +// GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } + + protected GridData createColumnLabelLayoutData() { + GridData layoutData = new GridData(SWT.CENTER, SWT.CENTER, false, false); + + return layoutData; + } + + protected GridData createComponentLayoutData() { + GridData layoutData = new GridData(SWT.FILL, SWT.TOP, true, false); + + return layoutData; + } + + private static GridLayout createLayout() { + GridLayout layout = new GridLayout(1, true); + GUIBuilderUtilities.clearMargins(layout); + GUIBuilderUtilities.clearSpacing(layout); + + return layout; + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ExpandableComponentWidget.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/FileSaveAs.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,52 @@ +package org.cishell.utilities.swt; + +import java.io.File; + +import org.cishell.utilities.StringUtilities; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; + +public class FileSaveAs { + public static final String DEFAULT_WINDOW_TITLE = "Save As"; + public static final String CONFIRMATION_DIALOG_FORMAT = + "%s already exists.\nDo you want to replace it?"; +// public static final String YES_BUTTON_LABEL = "Yes"; +// public static final String NO_BUTTON_LABEL = "No"; +// public static final String[] BUTTON_LABELS = { YES_BUTTON_LABEL, NO_BUTTON_LABEL }; + + public static String saveFileAs(Shell parent) { + FileDialog saveDialog = new FileDialog(parent); + saveDialog.setText(DEFAULT_WINDOW_TITLE); + + return saveFileAs(saveDialog); + } + + public static String saveFileAs(Shell parent, int style) { + FileDialog saveDialog = new FileDialog(parent, style); + saveDialog.setText(DEFAULT_WINDOW_TITLE); + + return saveFileAs(saveDialog); + } + + public static String saveFileAs(FileDialog saveDialog) { + while (true) { + String selectedFilePath = saveDialog.open(); + + if (StringUtilities.isNull_Empty_OrWhitespace(selectedFilePath)) { + return null; + } else { + if (new File(selectedFilePath).exists()) { + if (MessageDialog.openConfirm( + saveDialog.getParent(), + saveDialog.getText(), + String.format(CONFIRMATION_DIALOG_FORMAT, selectedFilePath))) { + return selectedFilePath; + } + } else { + return selectedFilePath; + } + } + } + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/FileSaveAs.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java (from rev 1101, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUIBuilderUtilities.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,124 @@ +package org.cishell.utilities.swt; + +import org.cishell.utilities.datastructure.ObjectContainer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ShellEvent; +import org.eclipse.swt.events.ShellListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; + +public class GUIBuilderUtilities { + public static Display createDisplay() { + return new Display(); + } + + public static Shell createShell( + Display display, + String windowTitle, + int windowWidth, + int windowHeight, + int columnCount, + boolean clearSpacing) { + Shell shell = new Shell(display, SWT.CLOSE | SWT.MIN | SWT.TITLE); + shell.setText(windowTitle); + shell.setSize(windowWidth, windowHeight); + shell.setLayout(createShellLayout(columnCount, clearSpacing)); + + return shell; + } + + public static GridLayout createShellLayout(int columnCount, boolean clearSpacing) { + GridLayout layout = new GridLayout(columnCount, true); + + if (clearSpacing) { + clearSpacing(layout); + } + + return layout; + } + + public static void openShell( + Shell shell, int windowHeight, boolean useWindowHeightToSizeShell) { +// if (useWindowHeightToSizeShell) { +// /* (So far, we've created the shell at the maximum possible size we'll allow +// * (according to windowHeight). This line shrinks the shell to be a more fitting size +// * if the actual contents (i.e. our (number of) columns) are smaller than the maximum +// * size we set.) +// */ +// Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); +// shell.setMinimumSize(shellSize.x, Math.min(windowHeight, shellSize.y)); +// } + + shell.pack(); + shell.open(); + + if (useWindowHeightToSizeShell) { + Point shellSize = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT); + shell.setSize(shell.getSize().x, Math.min(windowHeight, shellSize.y)); + } + } + + public static void swtLoop(Display display, Shell shell) { + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + + display.dispose(); + } + + public static void clearMargins(GridLayout layout) { + layout.marginTop = layout.marginBottom = layout.marginHeight = 0; + layout.marginLeft = layout.marginRight = layout.marginWidth = 0; + } + + public static void clearSpacing(GridLayout layout) { + layout.horizontalSpacing = layout.verticalSpacing = 0; + } + + public static void setCancelable( + final Shell shell, final ObjectContainer<GUICanceledException> exceptionThrown) { + shell.addListener(SWT.Traverse, new Listener() { + public void handleEvent(Event event) { + switch (event.detail) { + case SWT.TRAVERSE_ESCAPE: + shell.close(); + event.detail = SWT.TRAVERSE_NONE; + event.doit = false; + +// if (exceptionThrown != null) { +// String exceptionMessage = "Canceled by user."; +// exceptionThrown.object = new GUICanceledException(exceptionMessage); +// } + + break; + } + } + }); + shell.addShellListener(new ShellListener() { + public void shellActivated(ShellEvent event) { + } + + public void shellClosed(ShellEvent event) { + if (exceptionThrown != null) { + String exceptionMessage = "Canceled by user."; + exceptionThrown.object = new GUICanceledException(exceptionMessage); + } + } + + public void shellDeactivated(ShellEvent event) { + } + + public void shellDeiconified(ShellEvent event) { + } + + public void shellIconified(ShellEvent event) { + } + }); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUIBuilderUtilities.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GUICanceledException.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,21 @@ +package org.cishell.utilities.swt; + +public class GUICanceledException extends Exception { + private static final long serialVersionUID = 1L; + + public GUICanceledException() { + super(); + } + + public GUICanceledException(String arg0) { + super(arg0); + } + + public GUICanceledException(Throwable arg0) { + super(arg0); + } + + public GUICanceledException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GUICanceledException.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/GridContainer.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,92 @@ +package org.cishell.utilities.swt; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Widget; + +public class GridContainer { + private Composite actualParent; + private int columnCount; + private List<GridRow> rows = new ArrayList<GridRow>(); + + public GridContainer(Composite actualParent, int columnCount) { + this.actualParent = actualParent; + this.columnCount = columnCount; + } + + public Composite getActualParent() { + return this.actualParent; + } + + public int getColumnCount() { + return this.columnCount; + } + + public int getRowCount() { + return this.rows.size(); + } + + public GridRow addComponent(Widget component) { + GridRow lastRow = getOrCreateLastUsableRow(); + lastRow.addComponent(component); + + return lastRow; + } + + public void removeRow(int rowIndex) { + this.rows.get(rowIndex).dispose(); + this.rows.remove(rowIndex); + } + + private GridRow getOrCreateLastUsableRow() { + final int rowCount = getRowCount(); + + if (rowCount == 0) { + return addNewRow(); + } else { + GridRow lastRow = this.rows.get(rowCount - 1); + + if (lastRow.componentCount < getColumnCount()) { + return lastRow; + } else { + return addNewRow(); + } + } + } + + private GridRow addNewRow() { + GridRow row = new GridRow(getRowCount()); + this.rows.add(row); + + return row; + } + + public class GridRow { + private int rowIndex; + private int componentCount = 0; + private Collection<Widget> components = + new ArrayList<Widget>(GridContainer.this.columnCount); + + private GridRow(int rowIndex) { + this.rowIndex = rowIndex; + } + + public int getRowIndex() { + return this.rowIndex; + } + + private void addComponent(Widget component) { + this.components.add(component); + this.componentCount++; + } + + private void dispose() { + for (Widget component : this.components) { + component.dispose(); + } + } + } +} Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/GridContainer.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/SWTUtilities.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,123 @@ +package org.cishell.utilities.swt; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; + +public class SWTUtilities { + /* + * Append the given string to the console with the given color, this will do the job of + * checking for URLs within the string and registering the proper listeners on them as well. + */ + public static void appendStringWithURL( + StyledText textField, + URLClickedListener urlListener, + URLMouseCursorListener urlCursorListener, + String message, + Color normalColor, + Color urlColor) { + + //find a URL in the message + + int index = message.indexOf("http://"); + if (index == -1) { + index = message.indexOf("https://"); + } + if (index == -1) { + index = message.indexOf("www."); + } + + if (index > -1) { + String url = message.substring(index); + if (url.indexOf(") ") > -1) { + url = url.substring(0, url.indexOf(") ")); + } + else if (url.indexOf(" ") > -1) { + url = url.substring(0, url.indexOf(" ")); + if (url.trim().endsWith(".") ){ + url=url.substring(0, url.length()-1); + } + } + if (url.endsWith(".\n") || url.endsWith(".\t")){ + url=url.substring(0, url.length()-2); + } + if (url.indexOf("\n") > -1) { + url = url.substring(0, url.indexOf("\n")); + } + if (url.indexOf("\t") > -1) { + url = url.substring(0, url.indexOf("\n")); + } + + + syncedStyledPrint(textField, message.substring(0, index), normalColor, SWT.NORMAL); + urlListener.addURL(textField.getText().length(), url); + urlCursorListener.addURL(textField.getText().length(), url); + syncedStyledPrint(textField, url, urlColor, SWT.BOLD); + appendStringWithURL( + textField, + urlListener, + urlCursorListener, + message.substring(index + url.length()), + normalColor,urlColor); + } else { + syncedStyledPrint(textField, message, normalColor, SWT.NORMAL); + } + } + + /* + * Helper to actually format the string with a style range and + * append it to the StyledText control. + */ + + public static void syncedStyledPrint( + final StyledText textField, final String message, final Color color, final int style) { + Display.getDefault().syncExec(new Runnable() { + public void run(){ + styledPrint(textField, message, color, style); + } + }); + } + + public static void styledPrint(StyledText textField, String message, Color color, int style) { + if (!textField.isDisposed()) { + textField.append(message); + + StyleRange styleRange = new StyleRange(); + styleRange.start = textField.getText().length() - message.length(); + styleRange.length = message.length(); + styleRange.foreground = color; + styleRange.fontStyle = style; + textField.setStyleRange(styleRange); + + // This makes it autoscroll. + textField.setTopIndex(textField.getLineCount()); + } + } + + public static void printURL( + Composite parent, + StyledText textField, + String url, + String displayURL, + Color color, + int style) { + URLClickedListener urlClickedListener = new URLClickedListener(textField); + URLMouseCursorListener urlCursorListener = + new URLMouseCursorListener(parent, textField); + textField.addMouseListener(urlClickedListener); + textField.addMouseMoveListener(urlCursorListener); + + urlClickedListener.addURL( + textField.getText().length(), url, displayURL); + urlCursorListener.addURL( + textField.getText().length(), url, displayURL); + SWTUtilities.styledPrint( + textField, + displayURL, + color, + style); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/SWTUtilities.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/ScrolledComponentFactory.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,15 @@ +package org.cishell.utilities.swt; + +import java.util.Map; + +public interface ScrolledComponentFactory<T> { + public T constructWidget( + ExpandableComponentWidget<T> componentWidget, + GridContainer scrolledAreaGrid, + int style, + Map<String, Object> arguments, + int index, + int uniqueIndex); + + public void reindexComponent(T component, int newIndex); +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ScrolledComponentFactory.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLClickedListener.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,70 @@ +package org.cishell.utilities.swt; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.program.Program; + +/* + * Listens for clicks on urls and launches a browser. + */ +public class URLClickedListener extends MouseAdapter { + private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>(); + private Map<String, String> urlsToDisplayURLs = new HashMap<String, String>(); + private StyledText textField; + + public URLClickedListener(StyledText textField) { + super(); + this.textField = textField; + } + + public void addURL(int offset, String url) { + addURL(offset, url, url); + } + + public void addURL(int offset, String url, String displayURL) { + this.offsetsToURLs.put(offset, url); + this.urlsToDisplayURLs.put(url, displayURL); + } + + public void mouseDown(MouseEvent event) { + if (event.button != 1) { + return; + } + + int clickedPosition = determineClickedPosition(event); + + if (clickedPosition < 0) { + return; + } + + for (Integer offset : this.offsetsToURLs.keySet().toArray(new Integer[0])) { + String url = this.offsetsToURLs.get(offset); + String displayURL = this.urlsToDisplayURLs.get(url); + + if ((displayURL != null) && + (clickedPosition >= offset.intValue()) && + (clickedPosition <= (offset.intValue() + displayURL.length()))) { + try { + Program.launch(url); + } catch (Exception e) { + } + } + } + } + + private int determineClickedPosition(MouseEvent event) { + int clickedPosition = -1; + + try { + clickedPosition = this.textField.getOffsetAtLocation(new Point(event.x, event.y)); + } catch (IllegalArgumentException ex) { + } + + return clickedPosition; + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLClickedListener.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/URLMouseCursorListener.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,79 @@ +package org.cishell.utilities.swt; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseMoveListener; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; + +/* + * Monitors the mouse and changes the cursor when it is over a URL. + */ +public class URLMouseCursorListener implements MouseMoveListener { + private Map<Integer, String> offsetsToURLs = new HashMap<Integer, String>(); + private Map<String, String> urlsToDisplayURLs = new HashMap<String, String>(); + private Composite parent; + private StyledText textField; + + public URLMouseCursorListener(Composite parent, StyledText textField) { + this.parent = parent; + this.textField = textField; + } + + public void addURL(int offset, String url) { + addURL(offset, url, url); + } + + public void addURL(int offset, String url, String displayURL) { + this.offsetsToURLs.put(new Integer(offset), url); + this.urlsToDisplayURLs.put(url, displayURL); + } + + public void mouseMove(MouseEvent event) { + int urlOffsetOfMousePosition = determineURLOffsetOfMousePosition(event); + Integer[] urlOffsets = this.offsetsToURLs.keySet().toArray(new Integer[0]); + boolean mouseIsOverURL = determineIfMouseIsHoveringOverURL(urlOffsetOfMousePosition, urlOffsets); + Cursor cursor = new Cursor(parent.getDisplay(), determineMouseCursor(mouseIsOverURL)); + textField.setCursor(cursor); + } + + private int determineURLOffsetOfMousePosition(MouseEvent event) { + try { + return textField.getOffsetAtLocation(new Point(event.x, event.y)); + } catch (IllegalArgumentException e) { + Cursor cursor = new Cursor(parent.getDisplay(), SWT.CURSOR_ARROW); + textField.setCursor(cursor); + } + + return -1; + } + + private boolean determineIfMouseIsHoveringOverURL( + int urlOffsetOfMousePosition, Integer[] urlOffsets) { + for (Integer urlOffset : urlOffsets) { + String url = this.offsetsToURLs.get(urlOffset); + + if ((urlOffset != null) && + (url != null) && + (urlOffsetOfMousePosition >= urlOffset.intValue()) && + (urlOffsetOfMousePosition <= (urlOffset.intValue() + url.length()))) { + return true; + } + } + + return false; + } + + private int determineMouseCursor(boolean mouseIsOverURL) { + if (mouseIsOverURL) { + return SWT.CURSOR_HAND; + } else { + return SWT.CURSOR_ARROW; + } + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/URLMouseCursorListener.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModel.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,190 @@ +package org.cishell.utilities.swt.model; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.cishell.utilities.swt.model.datasynchronizer.CheckBoxDataSynchronizer; +import org.cishell.utilities.swt.model.datasynchronizer.DropDownDataSynchronizer; +import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; +import org.cishell.utilities.swt.model.datasynchronizer.SingleListSelectionDataSynchronizer; +import org.cishell.utilities.swt.model.datasynchronizer.TextDataSynchronizer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.Widget; + +public class GUIModel { + private Map<String, GUIModelGroup> groups = new HashMap<String, GUIModelGroup>(); + + public GUIModel() { + } + + public Collection<String> getGroupNames() { + return this.groups.keySet(); + } + + public Collection<GUIModelGroup> getGroups() { + return this.groups.values(); + } + + public GUIModelGroup getGroup(String name) { + if (!this.groups.containsKey(name)) { + GUIModelGroup newGroup = new GUIModelGroup(name); + this.groups.put(name, newGroup); + + return newGroup; + } else { + return this.groups.get(name); + } + } + + public GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> addCheckBox( + String groupName, String name, boolean on, Composite parent, int style) { + Button checkBox = new Button(parent, style | SWT.CHECK); + CheckBoxDataSynchronizer dataSynchronizer = new CheckBoxDataSynchronizer(checkBox, on); + GUIModelField<Boolean, Button, CheckBoxDataSynchronizer> field = + new GUIModelField<Boolean, Button, CheckBoxDataSynchronizer>( + name, on, checkBox, dataSynchronizer); + addField(groupName, field); + + return field; + } + + public GUIModelField<String, Combo, DropDownDataSynchronizer> addDropDown( + String groupName, + String name, + int selectedIndex, + Collection<String> unorderedOptionLabels, + Map<String, String> optionValuesByLabels, + Composite parent, + int style) { + java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels); + Combo dropDown = new Combo(parent, style | SWT.DROP_DOWN); + DropDownDataSynchronizer dataSynchronizer = new DropDownDataSynchronizer( + dropDown, selectedIndex, orderedOptionLabels, optionValuesByLabels); + GUIModelField<String, Combo, DropDownDataSynchronizer> field = + new GUIModelField<String, Combo, DropDownDataSynchronizer>( + name, + optionValuesByLabels.get(orderedOptionLabels.get(selectedIndex)), + dropDown, + dataSynchronizer); + addField(groupName, field); + + return field; + } + + // TODO: addMultiSelectionDropDown + + // TODO: Test this out. + // TODO: Make it so the build works with this stuff. +// public GUIModelField< +// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> +// addDate(String name, org.joda.time.DateTime date, Composite parent, int style) { +// org.eclipse.swt.widgets.DateTime dateSelector = +// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.DATE); +// DateDataSynchronizer dataSynchronizer = new DateDataSynchronizer(dateSelector, date); +// GUIModelField< +// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, DateDataSynchronizer> field = +// new GUIModelField< +// org.joda.time.DateTime, +// org.eclipse.swt.widgets.DateTime, +// DateDataSynchronizer>( +// name, date, dateSelector, dataSynchronizer); +// addField(field); +// +// return field; +// } + + // TODO: Test this out. +// public GUIModelField< +// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> +// addTime(String name, org.joda.time.DateTime time, Composite parent, int style) { +// org.eclipse.swt.widgets.DateTime timeSelector = +// new org.eclipse.swt.widgets.DateTime(parent, style | SWT.TIME); +// TimeDataSynchronizer dataSynchronizer = new TimeDataSynchronizer(timeSelector, time); +// GUIModelField< +// org.joda.time.DateTime, org.eclipse.swt.widgets.DateTime, TimeDataSynchronizer> field = +// new GUIModelField< +// org.joda.time.DateTime, +// org.eclipse.swt.widgets.DateTime, +// TimeDataSynchronizer>( +// name, time, timeSelector, dataSynchronizer); +// addField(field); +// +// return field; +// } + + // TODO: addCalendar + + // TODO: Test this out. + public GUIModelField<String, List, SingleListSelectionDataSynchronizer> addList( + String groupName, + String name, + int selectedIndex, + Collection<String> unorderedOptionLabels, + Map<String, String> optionValuesByLabels, + Composite parent, + int style) { + java.util.List<String> orderedOptionLabels = new ArrayList<String>(unorderedOptionLabels); + List list = new List(parent, style | SWT.SINGLE); + SingleListSelectionDataSynchronizer dataSynchronizer = + new SingleListSelectionDataSynchronizer( + list, selectedIndex, orderedOptionLabels, optionValuesByLabels); + GUIModelField<String, List, SingleListSelectionDataSynchronizer> field = + new GUIModelField<String, List, SingleListSelectionDataSynchronizer>( + name, list.getItem(selectedIndex), list, dataSynchronizer); + addField(groupName, field); + + return field; + } + + // TODO: addMultiSelectionList + // TODO: addProgressBar + // TODO: addSash? + // TODO: addSlider + // TODO: addScale + // TODO: addSpinner + // TODO: addStyledText + + public GUIModelField<String, Text, TextDataSynchronizer> addText( + String groupName, + String name, + String value, + boolean isMultiLined, + Composite parent, + int style) { + if (isMultiLined) { + style = style | SWT.MULTI; + } else { + style = style | SWT.SINGLE; + } + + Text text = new Text(parent, style); + TextDataSynchronizer dataSynchronizer = new TextDataSynchronizer(text, value); + GUIModelField<String, Text, TextDataSynchronizer> field = + new GUIModelField<String, Text, TextDataSynchronizer>( + name, value, text, dataSynchronizer); + addField(groupName, field); + + return field; + } + + public<T> void addField( + String groupName, + GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { + GUIModelGroup group = getGroup(groupName); + group.addField(field); + } + + public<T> void removeField( + GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { + for (GUIModelGroup group : this.groups.values()) { + group.removeField(field); + } + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModel.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelField.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,65 @@ +package org.cishell.utilities.swt.model; + +import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Widget; + +public class GUIModelField<T, U extends Widget, V extends ModelDataSynchronizer<T>> { + private String name; + private T defaultValue; + private T previousValue; + private T value; + private U widget; + private V dataSynchronizer; + + public GUIModelField( + String name, + T defaultValue, + U widget, + V dataSynchronizer) { + this.name = name; + this.defaultValue = defaultValue; + this.value = this.defaultValue; + this.widget = widget; + this.dataSynchronizer = dataSynchronizer; + + this.widget.addListener(this.dataSynchronizer.swtUpdateListenerCode(), new Listener() { + public void handleEvent(Event event) { + if (event.type == GUIModelField.this.dataSynchronizer.swtUpdateListenerCode()) { + GUIModelField.this.previousValue = GUIModelField.this.value; + GUIModelField.this.value = + GUIModelField.this.dataSynchronizer.synchronizeFromGUI(); + } + } + }); + } + + public String getName() { + return this.name; + } + + public T getPreviousValue() { + return this.previousValue; + } + + public T getValue() { + return this.value; + } + + public U getWidget() { + return this.widget; + } + + public V getDataSynchronizer() { + return this.dataSynchronizer; + } + + public void setValue(T value) { + this.value = this.dataSynchronizer.synchronizeToGUI(value); + } + + public void reset() { + this.value = this.dataSynchronizer.reset(this.defaultValue); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelField.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/GUIModelGroup.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,57 @@ +package org.cishell.utilities.swt.model; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.cishell.utilities.swt.model.datasynchronizer.ModelDataSynchronizer; +import org.eclipse.swt.widgets.Widget; + +public class GUIModelGroup { + private String name; + private Map<String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> + inputFieldsByName = new HashMap< + String, GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>>(); + + public GUIModelGroup(String name) { + this.name = name; + } + + public String getName() { + return this.name; + } + + public Collection<String> getFieldNames() { + return this.inputFieldsByName.keySet(); + } + + public Collection< + GUIModelField<?, ? extends Widget, ? extends ModelDataSynchronizer<?>>> getFields() { + return this.inputFieldsByName.values(); + } + + public GUIModelField< + ?, ? extends Widget, ? extends ModelDataSynchronizer<?>> getField(String name) { + return this.inputFieldsByName.get(name); + } + + public<T> void addField( + GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { + String fieldName = field.getName(); + + if (this.inputFieldsByName.containsKey(fieldName)) { + String exceptionMessage = + "A field with the name \"" + fieldName + "\" already exists. Unable to continue."; + throw new ModelFieldException(exceptionMessage); + } + + this.inputFieldsByName.put(fieldName, field); + } + + public<T> void removeField( + GUIModelField<T, ? extends Widget, ? extends ModelDataSynchronizer<?>> field) { + if (this.inputFieldsByName.containsValue(field)) { + this.inputFieldsByName.remove(field.getName()); + } + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/GUIModelGroup.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/ModelFieldException.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,21 @@ +package org.cishell.utilities.swt.model; + +public class ModelFieldException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public ModelFieldException() { + super(); + } + + public ModelFieldException(String arg0) { + super(arg0); + } + + public ModelFieldException(Throwable arg0) { + super(arg0); + } + + public ModelFieldException(String arg0, Throwable arg1) { + super(arg0, arg1); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/ModelFieldException.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,35 @@ +package org.cishell.utilities.swt.model.datasynchronizer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; + +public class CheckBoxDataSynchronizer implements ModelDataSynchronizer<Boolean> { + private Button checkBox; + + public CheckBoxDataSynchronizer(Button checkBox, boolean on) { + this.checkBox = checkBox; + this.checkBox.setSelection(on); + } + + public int swtUpdateListenerCode() { + return SWT.Selection; + } + + public Boolean value() { + return this.checkBox.getSelection(); + } + + public Boolean synchronizeFromGUI() { + return value(); + } + + public Boolean synchronizeToGUI(Boolean value) { + this.checkBox.setSelection(value); + + return value; + } + + public Boolean reset(Boolean defaultValue) { + return synchronizeToGUI(defaultValue); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/CheckBoxDataSynchronizer.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,42 @@ +//package org.cishell.utilities.swt.model.datasynchronizer; +// +//import org.eclipse.swt.SWT; +// +//public class DateDataSynchronizer implements ModelDataSynchronizer<org.joda.time.DateTime> { +// private org.eclipse.swt.widgets.DateTime dateSelector; +// +// public DateDataSynchronizer( +// org.eclipse.swt.widgets.DateTime dateSelector, org.joda.time.DateTime date) { +// this.dateSelector = dateSelector; +// synchronizeToGUI(date); +// } +// +// public int swtUpdateListenerCode() { +// return SWT.Selection; +// } +// +// public org.joda.time.DateTime value() { +// return new org.joda.time.DateTime( +// this.dateSelector.getYear(), +// this.dateSelector.getMonth(), +// this.dateSelector.getDay(), +// 0, +// 0, +// 0, +// 0); +// } +// +// public org.joda.time.DateTime synchronizeFromGUI() { +// return value(); +// } +// +// public org.joda.time.DateTime synchronizeToGUI(org.joda.time.DateTime date) { +// this.dateSelector.setDate(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth()); +// +// return value(); +// } +// +// public org.joda.time.DateTime reset(org.joda.time.DateTime defaultValue) { +// return synchronizeToGUI(defaultValue); +// } +//} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DateDataSynchronizer.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,61 @@ +package org.cishell.utilities.swt.model.datasynchronizer; + +import java.util.List; +import java.util.Map; + +import org.cishell.utilities.MapUtilities; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Combo; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +// TODO: Make this so options can change on it. +public class DropDownDataSynchronizer implements ModelDataSynchronizer<String> { + private Combo dropDown; + private BiMap<Integer, String> optionLabels; + private BiMap<String, String> optionValuesByLabels; + + public DropDownDataSynchronizer( + Combo dropDown, + int selectedIndex, + List<String> optionLabels, + Map<String, String> optionValuesByLabels) { + this.dropDown = dropDown; + + setOptions(optionLabels, optionValuesByLabels); + this.dropDown.select(selectedIndex); + } + + public int swtUpdateListenerCode() { + return SWT.Selection; + } + + public String value() { + return this.optionValuesByLabels.get( + this.optionLabels.get(this.dropDown.getSelectionIndex())); + } + + public String synchronizeFromGUI() { + return value(); + } + + public String synchronizeToGUI(String value) { + String label = this.optionValuesByLabels.inverse().get(value); + this.dropDown.select(this.optionLabels.inverse().get(label)); + + return value(); + } + + public String reset(String defaultValue) { + return synchronizeToGUI(defaultValue); + } + + public void setOptions(List<String> optionLabels, Map<String, String> optionValuesByLabels) { + this.optionLabels = HashBiMap.create(MapUtilities.mapIndexToValues(optionLabels)); + this.optionValuesByLabels = HashBiMap.create(optionValuesByLabels); + + this.dropDown.setItems(optionLabels.toArray(new String[0])); + this.dropDown.select(0); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/DropDownDataSynchronizer.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,9 @@ +package org.cishell.utilities.swt.model.datasynchronizer; + +public interface ModelDataSynchronizer<T> { + public int swtUpdateListenerCode(); + public T value(); + public T synchronizeFromGUI(); + public T synchronizeToGUI(T value); + public T reset(T defaultValue); +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/ModelDataSynchronizer.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,53 @@ +package org.cishell.utilities.swt.model.datasynchronizer; + +import java.util.Map; + +import org.cishell.utilities.MapUtilities; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.List; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +// TODO: Make this so options can change on it. +public class SingleListSelectionDataSynchronizer implements ModelDataSynchronizer<String> { + private List singleSelectionList; + private BiMap<Integer, String> optionLabels; + private Map<String, String> optionValuesByLabels; + + public SingleListSelectionDataSynchronizer( + List singleSelectionList, + int selectedIndex, + java.util.List<String> optionLabels, + Map<String, String> optionValuesByLabels) { + this.singleSelectionList = singleSelectionList; + this.optionLabels = HashBiMap.create(MapUtilities.mapIndexToValues(optionLabels)); + this.optionValuesByLabels = optionValuesByLabels; + + this.singleSelectionList.setItems(optionLabels.toArray(new String[0])); + this.singleSelectionList.select(selectedIndex); + } + + public int swtUpdateListenerCode() { + return SWT.Selection; + } + + public String value() { + return this.optionValuesByLabels.get( + this.optionLabels.get(this.singleSelectionList.getSelectionIndex())); + } + + public String synchronizeFromGUI() { + return this.optionLabels.get(this.singleSelectionList.getSelectionIndex()); + } + + public String synchronizeToGUI(String value) { + this.singleSelectionList.select(this.optionLabels.inverse().get(value)); + + return value(); + } + + public String reset(String defaultValue) { + return synchronizeToGUI(defaultValue); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/SingleListSelectionDataSynchronizer.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java (from rev 1098, trunk/core/org.cishell.utilities/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java) =================================================================== --- trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java (rev 0) +++ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java 2010-08-03 17:21:00 UTC (rev 1105) @@ -0,0 +1,36 @@ +package org.cishell.utilities.swt.model.datasynchronizer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Text; + +public class TextDataSynchronizer implements ModelDataSynchronizer<String> { + private Text text; + + public TextDataSynchronizer(Text text, String value) { + this.text = text; + + this.text.setText(value); + } + + public int swtUpdateListenerCode() { + return SWT.Modify; + } + + public String value() { + return this.text.getText(); + } + + public String synchronizeFromGUI() { + return value(); + } + + public String synchronizeToGUI(String value) { + this.text.setText(value); + + return value(); + } + + public String reset(String defaultValue) { + return synchronizeToGUI(defaultValue); + } +} \ No newline at end of file Property changes on: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/TextDataSynchronizer.java ___________________________________________________________________ Added: svn:mergeinfo + Copied: trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/model/datasynchronizer/TimeDataSynchronizer.java (from rev 1098, trunk/core/org.cishell.utilities/src/... [truncated message content] |
From: <pat...@us...> - 2010-08-03 17:18:45
|
Revision: 1104 http://cishell.svn.sourceforge.net/cishell/?rev=1104&view=rev Author: pataphil Date: 2010-08-03 17:18:39 +0000 (Tue, 03 Aug 2010) Log Message: ----------- * Changed the plugin description. Modified Paths: -------------- trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF Modified: trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF 2010-08-03 17:01:48 UTC (rev 1103) +++ trunk/core/org.cishell.utilities.datastructure/META-INF/MANIFEST.MF 2010-08-03 17:18:39 UTC (rev 1104) @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 -Bundle-Name: Datastructure Plug-in +Bundle-Name: CIShell Data Structure Utilities Bundle-SymbolicName: org.cishell.utilities.datastructure Bundle-Version: 1.0.0 Bundle-RequiredExecutionEnvironment: J2SE-1.5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-08-03 17:01:55
|
Revision: 1103 http://cishell.svn.sourceforge.net/cishell/?rev=1103&view=rev Author: pataphil Date: 2010-08-03 17:01:48 +0000 (Tue, 03 Aug 2010) Log Message: ----------- * Initial commit of org.cishell.utilities.swt. Added Paths: ----------- trunk/core/org.cishell.utilities.swt/.classpath trunk/core/org.cishell.utilities.swt/.project trunk/core/org.cishell.utilities.swt/.settings/ trunk/core/org.cishell.utilities.swt/.settings/org.eclipse.jdt.core.prefs trunk/core/org.cishell.utilities.swt/.settings/org.eclipse.pde.core.prefs trunk/core/org.cishell.utilities.swt/META-INF/ trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF trunk/core/org.cishell.utilities.swt/build.properties trunk/core/org.cishell.utilities.swt/src/ trunk/core/org.cishell.utilities.swt/src/org/ trunk/core/org.cishell.utilities.swt/src/org/cishell/ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/ trunk/core/org.cishell.utilities.swt/src/org/cishell/utilities/swt/ Added: trunk/core/org.cishell.utilities.swt/.classpath =================================================================== --- trunk/core/org.cishell.utilities.swt/.classpath (rev 0) +++ trunk/core/org.cishell.utilities.swt/.classpath 2010-08-03 17:01:48 UTC (rev 1103) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/core/org.cishell.utilities.swt/.project =================================================================== --- trunk/core/org.cishell.utilities.swt/.project (rev 0) +++ trunk/core/org.cishell.utilities.swt/.project 2010-08-03 17:01:48 UTC (rev 1103) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.cishell.utilities.swt</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Added: trunk/core/org.cishell.utilities.swt/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/core/org.cishell.utilities.swt/.settings/org.eclipse.jdt.core.prefs (rev 0) +++ trunk/core/org.cishell.utilities.swt/.settings/org.eclipse.jdt.core.prefs 2010-08-03 17:01:48 UTC (rev 1103) @@ -0,0 +1,7 @@ +#Tue Aug 03 12:42:22 EDT 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 Added: trunk/core/org.cishell.utilities.swt/.settings/org.eclipse.pde.core.prefs =================================================================== --- trunk/core/org.cishell.utilities.swt/.settings/org.eclipse.pde.core.prefs (rev 0) +++ trunk/core/org.cishell.utilities.swt/.settings/org.eclipse.pde.core.prefs 2010-08-03 17:01:48 UTC (rev 1103) @@ -0,0 +1,5 @@ +#Tue Aug 03 12:42:22 EDT 2010 +eclipse.preferences.version=1 +pluginProject.equinox=false +pluginProject.extensions=false +resolve.requirebundle=false Added: trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF (rev 0) +++ trunk/core/org.cishell.utilities.swt/META-INF/MANIFEST.MF 2010-08-03 17:01:48 UTC (rev 1103) @@ -0,0 +1,6 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: CIShell SWT Utilities +Bundle-SymbolicName: org.cishell.utilities.swt +Bundle-Version: 1.0.0 +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Added: trunk/core/org.cishell.utilities.swt/build.properties =================================================================== --- trunk/core/org.cishell.utilities.swt/build.properties (rev 0) +++ trunk/core/org.cishell.utilities.swt/build.properties 2010-08-03 17:01:48 UTC (rev 1103) @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |