From: <mwl...@us...> - 2009-04-24 22:00:54
|
Revision: 866 http://cishell.svn.sourceforge.net/cishell/?rev=866&view=rev Author: mwlinnem Date: 2009-04-24 22:00:50 +0000 (Fri, 24 Apr 2009) Log Message: ----------- 3 Things: Fixed CIShell menu to only include things really in CIShell, not things in NWB. Added a bunch of new icons from SciPolicy into CIShell as well. Made CIShell use a default icon instead of crashing and burning when it can't find an icon it wants. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.brand.cishell/extra-files/configuration/default_menu.xml trunk/clients/gui/org.cishell.reference.gui.datamanager/build.properties trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/database.jpg trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/matrix.png trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/plot.png trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/raster_image.jpg trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/vector_image.jpg trunk/clients/gui/org.cishell.reference.gui.datamanager/unknown.png Modified: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/extra-files/configuration/default_menu.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.brand.cishell/extra-files/configuration/default_menu.xml 2009-03-06 23:41:41 UTC (rev 865) +++ trunk/clients/gui/org.cishell.reference.gui.brand.cishell/extra-files/configuration/default_menu.xml 2009-04-24 22:00:50 UTC (rev 866) @@ -2,126 +2,23 @@ <!-- <?xml version="1.0" encoding="ISO-8859-1" ?> --> <menu_layout> <top_menu name="File"> - <menu name="Load..." pid= "org.cishell.reference.gui.persistence.load.FileLoad "/> - <menu name="Load CSV Files" pid= "edu.iu.nwb.preprocessing.csv.CsvAlgorithm"/> - <menu name="Directory Hierarchy Reader" pid= "edu.iu.nwb.preprocessing.prefuse.beta.directoryhierarchyreader.DirectoryHierarchyReaderAlgorithm"/> - <menu name = "Datasets" type="group"> - <menu name="Parallel Coordinates (demo) STF Dataset" pid="org.mediavirus.parvis.sampledata/pcvis_data.txt"/> - </menu> + <menu name="Load..." pid= "org.cishell.reference.gui.persistence.load.FileLoad "/> <menu type="break"/> <menu name="Save..." pid= "org.cishell.reference.gui.persistence.save.Save"/> <menu type="break"/> <menu name="View..." pid= "org.cishell.reference.gui.persistence.view.FileView"/> <menu name="View With..." pid= "org.cishell.reference.gui.persistence.viewwith.FileViewWith"/> <menu type="break"/> - <menu name = "Test" type="group"> - <menu name="Scheduler Tester" pid= "org.cishell.tests.ProgressTrackableAlgorithm.AlgorithmTest"/> - </menu> <menu type="break"/> <menu name="Exit" type="preserved"/> </top_menu> - <top_menu name="Preprocessing"> - <menu name="Random Node Deletion" pid="edu.iu.iv.errortolerance.ErrorToleranceAlgorithm"/> - <menu name="High Degree Node Deletion" pid="edu.iu.iv.attacktolerance.AttackToleranceAlgorithm"/> - <menu name="Pathfinder Network Scaling" pid="edu.iu.nwb.analysis.pathfindergraphnetworkscaling.PathfinderGraphAlgorithm"/> - <menu name="Multipartite Joining" pid="edu.iu.nwb.analysis.multipartitejoining.JoiningAlgorithm"/> - <menu type="break"/> - <menu name="Snowball Sampling (n nodes)" pid="edu.iu.nwb.analysis.sampling.snowball.SnowballAlgorithm"/> - <menu name="Node Sampling" pid="edu.iu.nwb.analysis.sampling.node.NodeAlgorithm"/> - <menu name="Edge Sampling" pid="edu.iu.nwb.analysis.sampling.edge.EdgeAlgorithm"/> - </top_menu> - <top_menu name="Modeling"> - <menu name="Random Graph" pid="edu.iu.nwb.modeling.erdosrandomgraph"/> - <menu name="Watts-Strogatz Small World" pid="edu.iu.nwb.modeling.smallworld"/> - <menu name="Barabási-Albert Scale-Free" pid="edu.iu.nwb.modeling.barabasialbert"/> - <menu type="break"/> - <menu name="Can" pid="edu.iu.iv.modeling.p2p.can.CanAlgorithm"/> - <menu name="Chord" pid="edu.iu.iv.modeling.p2p.chord.ChordAlgorithm"/> - <menu name="Hypergrid" pid="edu.id.iv.modeling.p2p.hypergrid.Hypergrid"/> - <menu name="PRU" pid="edu.iu.iv.modeling.p2p.pru.PruAlgorithm"/> - <menu type="break"/> - <menu name="TARL" pid="edu.iu.iv.modeling.tarl.TarlAlgorithm"/> - </top_menu> - <top_menu name="Analysis"> - <menu name = "Unweighted && Undirected" type="group"> - <menu name="Node Degree" pid="edu.iu.nwb.analysis.totaldegreesequence"/> - <menu name="Degree Distribution" pid="edu.iu.nwb.analysis.totaldegreedistribution"/> - <menu type="break"/> - <menu name="k-Nearest Neighbor" pid="edu.iu.nwb.analysis.undirectedknn"/> - <menu name="Watts Strogatz Clustering Coefficient" pid="edu.iu.nwb.analysis.clustering"/> - <menu name="Watts Strogatz Clustering Coefficient Over k" pid="edu.iu.nwb.analysis.clustering_vs_k"/> - <menu type="break"/> - <menu name="Diameter" pid="edu.iu.nwb.analysis.diameter"/> - <menu name="Average Shortest Path" pid="edu.iu.nwb.analysis.averageshortestpath"/> - <menu name="Shortest Path Distribution" pid="edu.iu.nwb.analysis.shortestpathdistr"/> - <menu name="Node Betweenness Centrality" pid="edu.iu.nwb.analysis.sitebetweenness"/> - <menu type="break"/> - <menu name="Connected Components" pid="edu.iu.nwb.analysis.connectedcomponents"/> - <menu name="Weak Component Clustering" pid="edu.iu.nwb.analysis.weakcomponentclustering.ClusteringAlgorithm"/> - </menu> - - <menu name = "Unweighted && Directed" type="group"> - <menu name="Node Indegree" pid="edu.iu.nwb.analysis.indegreesequence"/> - <menu name="Node Outdegree" pid="edu.iu.nwb.analysis.outdegreesequence"/> - <menu name="Indegree Distribution" pid="edu.iu.nwb.analysis.indegreedistribution"/> - <menu name="Outdegree Distribution" pid="edu.iu.nwb.analysis.outdegreedistribution"/> - <menu type="break"/> - <menu name="k-Nearest Neighbor" pid="edu.iu.nwb.analysis.directedknn"/> - <menu name="Single Node In-Out Degree Correlations" pid="edu.iu.nwb.analysis.onepointcorrelations"/> - <menu type="break"/> - <menu name="Page Rank" pid="edu.iu.nwb.analysis.pagerank"/> - </menu> - - <menu name = "Weighted and Undirected" type="group"> - </menu> - <menu name = "Weighted and Directed" type="group"> - </menu> - </top_menu> - - <top_menu name="Search"> - <menu name="Can" pid="edu.iu.iv.search.p2p.can.CanSearchAlgorithm"/> - <menu name="Chord" pid="edu.iu.iv.search.p2p.chord.ChordSearchAlgorithm"/> - <menu name="k Random-Walk" pid="edu.iu.iv.search.p2p.randomwalk.RandomWalkAlgorithm"/> - <menu name="Random Breadth First" pid="edu.iu.iv.search.p2p.bfs.BreadthFirstSearchAlgorithm"/> - </top_menu> - - <top_menu name="Clustering"> - <menu name="Weak Component Clustering" pid="edu.iu.nwb.analysis.weakcomponentclustering.ClusteringAlgorithm"/> - </top_menu> - - <top_menu name="Visualization"> - <menu name="Circular" pid="edu.iu.nwb.visualization.jungnetworklayout.JUNGCircleLayout"/> - <menu name="Specified" pid="edu.iu.nwb.visualization.prefuse.beta.specified.Specified"/> - <menu type="break"/> - <menu name="Radial Tree/Graph" pid="edu.iu.nwb.visualization.radialgraph.RadialGraph"/> - <menu name="Radial Tree/Graph with Annotation" pid="edu.iu.nwb.visualization.prefuse.beta.radialgraph.RadialGraph"/> - <menu name="Tree Map" pid="edu.iu.nwb.visualization.prefuse.beta.treemap.TreeMap"/> - <menu name="Tree View" pid="edu.iu.nwb.visualization.prefuse.beta.treeview.TreeView"/> - <menu type="break"/> - <menu name="Force Directed" pid="edu.iu.nwb.visualization.prefuse.beta.graphview.GraphView"/> - <menu name="Kamada-Kawai" pid="edu.iu.nwb.visualization.jungnetworklayout.JUNGKamadaKawaiLayout"/> - <menu name="Fruchterman-Reingold" pid="edu.iu.nwb.visualization.jungnetworklayout.JUNGFruchtermanReingoldLayout"/> - <menu name="Fruchterman-Reingold with Annotation" pid="edu.iu.nwb.visualization.prefuse.beta.fruchtermanreingold.FruchtermanReingold"/> - <menu name="Spring" pid="edu.iu.nwb.visualization.jungnetworklayout.JUNGSpringLayout"/> - <menu name="Small World" pid="edu.iu.nwb.visualization.prefuse.alpha.smallworld.app.SmallWorld"/> - <menu type="break"/> - <menu name="Parallel Coordinates (demo)" pid="org.mediavirus.parvis.ParallelCoordinatesAlgorithm"/> - </top_menu> - <top_menu name="Tools"> - <menu name="GnuPlot" pid="edu.iu.nwb.visualization.gnuplot"/> <menu name="Scheduler" pid=""/> </top_menu> <top_menu name="Help"> - <menu name="Dataset Details" pid=""/> - <menu name="Algorithm Details" pid=""/> - <menu name="Tutorials" pid=""/> - <menu type="break"/> <menu name="Update" pid=""/> <menu name="Manage Configuration" pid=""/> - <menu type="break"/> - <menu name="About Network Workbench Tool" pid=""/> </top_menu> </menu_layout> Added: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/database.jpg =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/database.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/matrix.png =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/matrix.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/plot.png =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/plot.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/raster_image.jpg =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/raster_image.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/vector_image.jpg =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/icons/vector_image.jpg ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/build.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/build.properties 2009-03-06 23:41:41 UTC (rev 865) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/build.properties 2009-04-24 22:00:50 UTC (rev 866) @@ -1,4 +1,6 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . \ No newline at end of file + .,\ + unknown.png + Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java 2009-03-06 23:41:41 UTC (rev 865) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java 2009-04-24 22:00:50 UTC (rev 866) @@ -15,6 +15,7 @@ import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; @@ -62,16 +63,16 @@ children = new ArrayList(); this.brandPluginID = brandPluginID; - matrixIcon = createImage("matrix.png", this.brandPluginID); - treeIcon = createImage("tree.png", this.brandPluginID); - networkIcon = createImage("network.png", this.brandPluginID); - unknownIcon = createImage("unknown.png", this.brandPluginID); - textIcon = createImage("text.png", this.brandPluginID); - plotIcon = createImage("plot.png", this.brandPluginID); - tableIcon = createImage("table.png", this.brandPluginID); - databaseIcon = createImage("database.jpg", this.brandPluginID); - rasterImageIcon = createImage("raster_image.jpg", this.brandPluginID); - vectorImageIcon = createImage("vector_image.jpg", this.brandPluginID); + matrixIcon = getImage("matrix.png", this.brandPluginID); + treeIcon = getImage("tree.png", this.brandPluginID); + networkIcon = getImage("network.png", this.brandPluginID); + unknownIcon = getImage("unknown.png", this.brandPluginID); + textIcon = getImage("text.png", this.brandPluginID); + plotIcon = getImage("plot.png", this.brandPluginID); + tableIcon = getImage("table.png", this.brandPluginID); + databaseIcon = getImage("database.jpg", this.brandPluginID); + rasterImageIcon = getImage("raster_image.jpg", this.brandPluginID); + vectorImageIcon = getImage("vector_image.jpg", this.brandPluginID); typeToImageMapping = new HashMap(); registerImage(DataProperty.OTHER_TYPE, unknownIcon); @@ -157,15 +158,43 @@ typeToImageMapping.put(type, image); } - public static Image createImage(String name, String brandPluginID){ - if(Platform.isRunning()){ - return AbstractUIPlugin. - imageDescriptorFromPlugin(brandPluginID, - File.separator + "icons" + File.separator + name). - createImage(); + + + public static Image getImage(String name, String brandPluginID){ + if(Platform.isRunning()) { + String imageLocation = File.separator + "icons" + File.separator + name; + ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( + brandPluginID, + imageLocation); + if (imageDescriptor != null) { + return imageDescriptor.createImage(); + } else { + System.err.println("Could not find the icon " + + "'" + imageLocation + "'" + + "in" + + "'" + brandPluginID + "'." + + "Using the default image instead."); + return getDefaultImage(); + } + } else { - return null; + System.err.println("Could not obtain the image " + + "'" + name + "'" + + "in" + + "'" + brandPluginID + "'" + + ", since the platform was not running (?)." + + "Using the default image instead."); + return getDefaultImage(); } } + + private static final String DEFAULT_IMAGE_LOCATION = File.separator + "unknown.png"; + + private static Image getDefaultImage() { + String thisPluginID = "org.cishell.reference.gui.datamanager"; //TODO: don't hardcode this + ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( + thisPluginID, DEFAULT_IMAGE_LOCATION); + return imageDescriptor.createImage(); + } } Added: trunk/clients/gui/org.cishell.reference.gui.datamanager/unknown.png =================================================================== (Binary files differ) Property changes on: trunk/clients/gui/org.cishell.reference.gui.datamanager/unknown.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-05-28 18:53:09
|
Revision: 1068 http://cishell.svn.sourceforge.net/cishell/?rev=1068&view=rev Author: pataphil Date: 2010-05-28 18:53:00 +0000 (Fri, 28 May 2010) Log Message: ----------- * Refactored File Load code to not suck so bad. * Reviewed by Joseph. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.brand.cishell/extra-files/configuration/default_menu.xml trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java Modified: trunk/clients/gui/org.cishell.reference.gui.brand.cishell/extra-files/configuration/default_menu.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.brand.cishell/extra-files/configuration/default_menu.xml 2010-05-28 18:18:24 UTC (rev 1067) +++ trunk/clients/gui/org.cishell.reference.gui.brand.cishell/extra-files/configuration/default_menu.xml 2010-05-28 18:53:00 UTC (rev 1068) @@ -2,7 +2,7 @@ <!-- <?xml version="1.0" encoding="ISO-8859-1" ?> --> <menu_layout> <top_menu name="File"> - <menu name="Load..." pid= "org.cishell.reference.gui.persistence.load.FileLoad "/> + <menu name="Load..." pid= "org.cishell.reference.gui.persistence.load.FileLoadAlgorithm "/> <menu type="break"/> <menu name="Save..." pid= "org.cishell.reference.gui.persistence.save.Save"/> <menu type="break"/> Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2010-05-28 18:18:24 UTC (rev 1067) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2010-05-28 18:53:00 UTC (rev 1068) @@ -4,7 +4,7 @@ description=This allows users to select file from the file system and load it to Data Model window in_data=null out_data=java.lang.Object -service.pid=org.cishell.reference.gui.persistence.load.FileLoad +service.pid=org.cishell.reference.gui.persistence.load.FileLoadAlgorithm remoteable=true prefs_published=local receive_prefs=true Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml 2010-05-28 18:18:24 UTC (rev 1067) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml 2010-05-28 18:53:00 UTC (rev 1068) @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<component name="org.cishell.reference.gui.persistence.load.FileLoad.component" immediate="false"> +<component name="org.cishell.reference.gui.persistence.load.FileLoadAlgorithm.component" immediate="false"> <implementation class="org.cishell.reference.gui.persistence.load.FileLoadFactory"/> <properties entry="OSGI-INF/load.properties"/> <reference name="LOG" interface="org.osgi.service.log.LogService"/> Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML 2010-05-28 18:18:24 UTC (rev 1067) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML 2010-05-28 18:53:00 UTC (rev 1068) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"> - <OCD name="File Load" id="org.cishell.reference.gui.persistence.load.FileLoad.prefs.local.OCD" + <OCD name="File Load" id="org.cishell.reference.gui.persistence.load.FileLoadAlgorithm.prefs.local.OCD" description=" "> <AD name="Default load directory" id="loadDir" type="String" default="directory:sampledata/"/> </OCD> @@ -8,8 +8,8 @@ description=" "> <AD name="View With" id="viewWith" type="String" default=""/> </OCD> - <Designate pid="org.cishell.reference.gui.persistence.load.FileLoad.prefs.local"> - <Object ocdref="org.cishell.reference.gui.persistence.load.FileLoad.prefs.local.OCD" /> + <Designate pid="org.cishell.reference.gui.persistence.load.FileLoadAlgorithm.prefs.local"> + <Object ocdref="org.cishell.reference.gui.persistence.load.FileLoadAlgorithm.prefs.local.OCD" /> </Designate> <Designate pid="org.cishell.reference.gui.persistence.viewwith.FileViewWith"> <Object ocdref="org.cishell.reference.gui.persistence.viewwith.FileViewWith.OCD" /> Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2010-05-28 18:18:24 UTC (rev 1067) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2010-05-28 18:53:00 UTC (rev 1068) @@ -6,13 +6,7 @@ */ package org.cishell.reference.gui.persistence.load; -import java.io.File; -import java.util.ArrayList; - -import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.data.BasicData; -import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.common.AbstractDialog; import org.eclipse.swt.SWT; @@ -30,17 +24,12 @@ import org.eclipse.swt.widgets.Shell; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; public class FileFormatSelector extends AbstractDialog { - private File selectedFile; - private LogService logger; - private ServiceReference[] persisterArray; - private List persisterList; -// private StyledText detailPane; - private CIShellContext ciShellContext; private BundleContext bundleContext; - private ArrayList returnList; + private AlgorithmFactory validator; + private ServiceReference[] validatorReferences; + private List validatorList; // private static final String[] DETAILS_ITEM_KEY = // {"format_name", "supported_file_extension", "format_description" }; @@ -59,19 +48,12 @@ public FileFormatSelector( String title, - File selectedFile, Shell parent, - CIShellContext ciShellContext, - BundleContext bundleContext, - ServiceReference[] persisterArray, - ArrayList returnList) { + BundleContext bundleContext, + ServiceReference[] validatorReferences) { super(parent, title, AbstractDialog.QUESTION); - this.ciShellContext = ciShellContext; this.bundleContext = bundleContext; - this.persisterArray = persisterArray; - this.returnList = returnList; - this.selectedFile = selectedFile; - this.logger = (LogService)ciShellContext.getService(LogService.class.getName()); + this.validatorReferences = validatorReferences; // Shall this part be moved out of the code? setDescription( @@ -82,8 +64,12 @@ "This dialog allows the user to choose among all available " + "formats for loading the selected data model. Choose any of the formats " + "to continue loading the dataset."); - } + } + public AlgorithmFactory getValidator() { + return this.validator; + } + private Composite initializeGUI(Composite parent) { Composite content = new Composite(parent, SWT.NONE); @@ -91,18 +77,18 @@ layout.numColumns = 1; content.setLayout(layout); - Group persisterGroup = new Group(content, SWT.NONE); + Group validatorGroup = new Group(content, SWT.NONE); // Shall this label be moved out of the code? - persisterGroup.setText("Load as..."); - persisterGroup.setLayout(new FillLayout()); - GridData persisterListGridData = new GridData(GridData.FILL_BOTH); - persisterListGridData.widthHint = 200; - persisterGroup.setLayoutData(persisterListGridData); + validatorGroup.setText("Load as..."); + validatorGroup.setLayout(new FillLayout()); + GridData validatorListGridData = new GridData(GridData.FILL_BOTH); + validatorListGridData.widthHint = 200; + validatorGroup.setLayoutData(validatorListGridData); - this.persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); + this.validatorList = new List(validatorGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); // initPersisterArray(); initializePersisterList(); - this.persisterList.addMouseListener(new MouseAdapter() { + this.validatorList.addMouseListener(new MouseAdapter() { public void mouseDoubleClick(MouseEvent mouseEvent) { List list = (List)mouseEvent.getSource(); int selection = list.getSelectionIndex(); @@ -113,109 +99,70 @@ } }); - this.persisterList.addSelectionListener(new SelectionAdapter() { + this.validatorList.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent selectionEvent) { List list = (List)selectionEvent.getSource(); int selection = list.getSelectionIndex(); if (selection != -1) { - // updateDetailPane(persisterArray[selection]); + // updateDetailPane(validatorReferences[selection]); } } }); - persisterList.setSelection(0); + validatorList.setSelection(0); - /* Group detailsGroup = new Group(content, SWT.NONE); - // Shall this label be moved out of the code? - detailsGroup.setText("Details"); - detailsGroup.setLayout(new FillLayout()); - GridData detailsGridData = new GridData(GridData.FILL_BOTH); - detailsGridData.widthHint = 200; - detailsGroup.setLayoutData(detailsGridData); - - detailPane = initDetailPane(detailsGroup); - - persisterList.setSelection(0); - updateDetailPane(persisterArray[0]); */ - return content; } private void initializePersisterList() { - for (int ii = 0; ii < this.persisterArray.length; ++ii) { - String name = (String)this.persisterArray[ii].getProperty("label"); + for (int ii = 0; ii < this.validatorReferences.length; ++ii) { + String name = (String)this.validatorReferences[ii].getProperty("label"); /* * If someone was sloppy enough to not provide a name, then use the name of the * class instead. */ if (name == null || name.length() == 0) { - name = this.persisterArray[ii].getClass().getName(); + name = this.validatorReferences[ii].getClass().getName(); } - this.persisterList.add(name); + this.validatorList.add(name); } } - - /* private StyledText initDetailPane(Group detailsGroup) { - StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); - detailPane.setEditable(false); - detailPane.getCaret().setVisible(false); - - return detailPane; - }*/ - - /* private void updateDetailPane(ServiceReference persister) { - - detailPane.setText(""); - - for (int ii = 0; ii < DETAILS_ITEM_KEY.length; ii++){ - String val = (String)persister.getProperty(DETAILS_ITEM_KEY[ii]); - - StyleRange styleRange = new StyleRange(); - styleRange.start = detailPane.getText().length(); - detailPane.append(DETAILS_ITEM_KEY_DISPLAY_VALUE[ii] + ":\n"); - styleRange.length = DETAILS_ITEM_KEY[ii].length() + 1; - styleRange.fontStyle = SWT.BOLD; - detailPane.setStyleRange(styleRange); - - detailPane.append(val + "\n"); - } - } */ - private void selectionMade(int selectedIndex) { - AlgorithmFactory persister = - (AlgorithmFactory)this.bundleContext.getService(this.persisterArray[selectedIndex]); - Data[] data = null; - boolean loadSuccess = false; - - try { - data = - new Data[] { new BasicData(this.selectedFile.getPath(), String.class.getName()) }; - data = persister.createAlgorithm(data, null, this.ciShellContext).execute(); - loadSuccess = true; - } catch (Throwable exception) { - this.logger.log( - LogService.LOG_ERROR, "Error occurred while executing selection", exception); - exception.printStackTrace(); - loadSuccess = false; - } - - if ((data != null) && loadSuccess) { - this.logger.log(LogService.LOG_INFO, "Loaded: " + this.selectedFile.getPath()); - - for (int ii = 0; ii < data.length; ii++) { - Data dataItem = data[ii]; - FileLoad.relabelWithFilename(dataItem, selectedFile); - this.returnList.add(dataItem); - } - - close(true); - } else { - this.logger.log(LogService.LOG_ERROR, "Unable to load with selected loader"); - } + this.validator = + (AlgorithmFactory)this.bundleContext.getService(this.validatorReferences[selectedIndex]); + close(true); +// AlgorithmFactory validator = +// (AlgorithmFactory)this.bundleContext.getService(this.persisterArray[selectedIndex]); +// Data[] data = null; +// boolean loadSuccess = false; +// +// try { +// data = +// new Data[] { new BasicData(this.selectedFile.getPath(), String.class.getName()) }; +// data = validator.createAlgorithm(data, null, this.ciShellContext).execute(); +// loadSuccess = true; +// } catch (Throwable exception) { +// this.logger.log( +// LogService.LOG_ERROR, "Error occurred while executing selection", exception); +// exception.printStackTrace(); +// loadSuccess = false; +// } +// +// if ((data != null) && loadSuccess) { +// this.logger.log(LogService.LOG_INFO, "Loaded: " + this.selectedFile.getPath()); +// +// for (int ii = 0; ii < data.length; ii++) { +// this.returnList.add(data[ii]); +// } +// +// close(true); +// } else { +// this.logger.log(LogService.LOG_ERROR, "Unable to load with selected loader"); +// } } public void createDialogButtons(Composite parent) { @@ -223,7 +170,7 @@ select.setText("Select"); select.addSelectionListener(new SelectionAdapter(){ public void widgetSelected(SelectionEvent selectionEvent) { - int index = FileFormatSelector.this.persisterList.getSelectionIndex(); + int index = FileFormatSelector.this.validatorList.getSelectionIndex(); if (index != -1) { selectionMade(index); Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2010-05-28 18:18:24 UTC (rev 1067) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2010-05-28 18:53:00 UTC (rev 1068) @@ -1,302 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Dictionary; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.AlgorithmExecutionException; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.data.BasicData; -import org.cishell.framework.data.Data; -import org.cishell.framework.data.DataProperty; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; - -public class FileLoad implements Algorithm { - - private final LogService logger; - - private BundleContext bundleContext; - private CIShellContext ciShellContext; - private static String defaultLoadDirectory; - - public FileLoad(CIShellContext ciContext, BundleContext bContext, - Dictionary prefProperties) { - this.ciShellContext = ciContext; - this.bundleContext = bContext; - logger = (LogService) ciContext.getService(LogService.class.getName()); - - // unpack preference properties - if (defaultLoadDirectory == null) { - - /* - * get the default load directory from preferences, - * if it has been set. - */ - Object result = prefProperties.get("loadDir"); - if (result != null) { - defaultLoadDirectory = (String) result; - } else { - defaultLoadDirectory = ""; - } - } - } - - protected static void relabelWithFilename(Data data, File file) { - File absoluteFile; - try { - absoluteFile = file.getCanonicalFile(); - } catch (IOException e) { - absoluteFile = file.getAbsoluteFile(); - } - File parent; - try { - parent = absoluteFile.getParentFile().getCanonicalFile(); - } catch (IOException e) { - parent = absoluteFile.getParentFile().getAbsoluteFile(); - } - String prefix; - String parentName = parent.getName(); - if(parentName.trim().length() == 0) { - prefix = File.separator; - } else { - prefix = "..." + File.separator + parentName + File.separator; - } - data.getMetadata().put(DataProperty.LABEL, prefix + absoluteFile.getName()); - } - - public Data[] execute() throws AlgorithmExecutionException { - // prepare to run load dialog in GUI thread - - IWorkbenchWindow window = getFirstWorkbenchWindow(); - Display display = PlatformUI.getWorkbench().getDisplay(); - FileLoadRunnable fileLoader = new FileLoadRunnable(window); - - // run load dialog in gui thread. - - if (Thread.currentThread() != display.getThread()) { - display.syncExec(fileLoader); - } else { - fileLoader.run(); - } - - // return loaded file data - - Data[] loadedFileData = extractLoadedFileData(fileLoader); - return loadedFileData; - } - - final class FileLoadRunnable implements Runnable { - boolean loadFileSuccess = false; - IWorkbenchWindow window; - - // this is how we return values from the runnable - public ArrayList loadedFiles_ReturnParameter = new ArrayList(); - - FileLoadRunnable(IWorkbenchWindow window) { - this.window = window; - } - - /* - * Let the user chose which file to load, - * Let the user choose the file type (if it is ambiguous), - * and then actually load and validate the file. - */ - public void run() { - try { - // Prepare to ask the user which file to load. - - FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN); - File currentDir = new File(defaultLoadDirectory); - String absolutePath = currentDir.getAbsolutePath(); - dialog.setFilterPath(absolutePath); - dialog.setText("Select a File"); - - // Determine which file to load. - - String nameOfFileToLoad = dialog.open(); - if (nameOfFileToLoad == null) { - return; - } - - // Actually load the file. - - File file = new File(nameOfFileToLoad); - - if (file.isDirectory()) { - defaultLoadDirectory = file.getAbsolutePath(); - } else { - defaultLoadDirectory = file.getParentFile().getAbsolutePath(); - } - - //Validate the loaded file, "casting" it to a certain MIME type. - - // Extract the file's file extension. - - String fileExtension = getFileExtension(file).toLowerCase(); - - // Get all the validators which support this file extension... - - ServiceReference[] supportingValidators = getSupportingValidators(fileExtension); - - // If there are no supporting validators... - if (supportingValidators.length == 0) { - // Let the user choose from all the validators available. - - ServiceReference[] allValidators = getAllValidators(); - - new FileFormatSelector("Load", file, window.getShell(), - ciShellContext, bundleContext, allValidators, - loadedFiles_ReturnParameter).open(); - } - - // If there is just one supporting validator... - if (supportingValidators.length == 1) { - // Just use that validator to validate the file. - - ServiceReference onlyPossibleValidator = supportingValidators[0]; - AlgorithmFactory selectedValidatorExecutor = (AlgorithmFactory) bundleContext - .getService(onlyPossibleValidator); - Data[] outputDataAfterValidation; - Data[] inputDataForValidation = new Data[] { new BasicData( - file.getPath(), String.class.getName()) }; - outputDataAfterValidation = selectedValidatorExecutor - .createAlgorithm(inputDataForValidation, null, - ciShellContext).execute(); - - /* - * outputDataAfterValidation = null implies that file - * was not loaded properly. - */ - - if (outputDataAfterValidation != null) { - loadFileSuccess = true; - logger.log(LogService.LOG_INFO, "Loaded: " - + file.getPath()); - for (int i = 0; i < outputDataAfterValidation.length; i++) { - Data data = outputDataAfterValidation[i]; - relabelWithFilename(data, file); - loadedFiles_ReturnParameter.add(data); - } - } - } - - // If there is more than one supporting validator... - if (supportingValidators.length > 1) { - // Let the user choose which validator they want to use. - - new FileFormatSelector("Load", file, window.getShell(), - ciShellContext, bundleContext, supportingValidators, - loadedFiles_ReturnParameter).open(); - } - - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - - - private ServiceReference[] getSupportingValidators(String fileExtension) { - try { - String ldapQuery = "(& (type=validator)" + - "(|" + - "(in_data=file-ext:" + fileExtension + ")" + - "(also_validates=" + fileExtension + ")" + - "))"; - - ServiceReference[] supportingValidators = - bundleContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), - ldapQuery); - - - if (supportingValidators == null) { - //(better to return a list of length zero than null) - supportingValidators = new ServiceReference[]{}; - } - - return supportingValidators; - - - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - return new ServiceReference[]{}; - } - } - - private ServiceReference[] getAllValidators() { - try { - ServiceReference[] allValidators = - bundleContext.getAllServiceReferences( - AlgorithmFactory.class.getName(), - "(&(type=validator)(in_data=file-ext:*))"); - - if (allValidators == null) { - //(better to return a list of length zero than null) - allValidators = new ServiceReference[]{}; - } - - return allValidators; - - } catch (InvalidSyntaxException e) { - e.printStackTrace(); - return new ServiceReference[]{}; - } - } - - public String getFileExtension(File theFile) { - String fileName = theFile.getName(); - String extension; - if (fileName.lastIndexOf(".") != -1) - extension = fileName.substring(fileName.lastIndexOf(".") + 1); - else - extension = ""; - return extension; - } - } - - private IWorkbenchWindow getFirstWorkbenchWindow() - throws AlgorithmExecutionException { - final IWorkbenchWindow[] windows = PlatformUI.getWorkbench() - .getWorkbenchWindows(); - if (windows.length == 0) { - throw new AlgorithmExecutionException( - "Cannot obtain workbench window needed to open dialog."); - } else { - return windows[0]; - } - } - - private Data[] extractLoadedFileData(FileLoadRunnable dataUpdater) - throws AlgorithmExecutionException { - Data[] loadedFileData; - try { - if (!dataUpdater.loadedFiles_ReturnParameter.isEmpty()) { - int size = dataUpdater.loadedFiles_ReturnParameter.size(); - loadedFileData = new Data[size]; - for (int index = 0; index < size; index++) { - loadedFileData[index] = (Data) dataUpdater.loadedFiles_ReturnParameter - .get(index); - } - return loadedFileData; - } else { - this.logger - .log(LogService.LOG_WARNING, "File loading canceled"); - return new Data[0]; - } - } catch (Throwable e2) { - throw new AlgorithmExecutionException(e2); - } - } -} \ No newline at end of file Copied: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java (from rev 1041, trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java) =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2010-05-28 18:53:00 UTC (rev 1068) @@ -0,0 +1,98 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; +import java.util.Collection; +import java.util.Dictionary; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.algorithm.ProgressMonitor; +import org.cishell.framework.algorithm.ProgressTrackable; +import org.cishell.framework.data.Data; +import org.cishell.utilities.StringUtilities; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.osgi.framework.BundleContext; +import org.osgi.service.log.LogService; + +public class FileLoadAlgorithm implements Algorithm, ProgressTrackable { + public static final String LOAD_DIRECTORY_PREFERENCE_KEY = "loadDir"; + + public static String defaultLoadDirectory; + + private final LogService logger; + private BundleContext bundleContext; + private CIShellContext ciShellContext; + private ProgressMonitor progressMonitor = ProgressMonitor.NULL_MONITOR; + + public FileLoadAlgorithm( + CIShellContext ciShellContext, + BundleContext bundleContext, + Dictionary<String, Object> preferences) { + this.logger = (LogService)ciShellContext.getService(LogService.class.getName()); + this.ciShellContext = ciShellContext; + this.bundleContext = bundleContext; + + // This is not done upon declaration because the preference service may not have started. + if (FileLoadAlgorithm.defaultLoadDirectory == null) { + FileLoadAlgorithm.defaultLoadDirectory = determineDefaultLoadDirectory(preferences); + } + } + + public Data[] execute() throws AlgorithmExecutionException { + // Prepare to run load dialog in GUI thread. + + IWorkbenchWindow window = getFirstWorkbenchWindow(); + Display display = PlatformUI.getWorkbench().getDisplay(); + FileLoadUserInputRunnable userInputGetter = new FileLoadUserInputRunnable( + window, this.bundleContext, this.ciShellContext); + + // Run load dialog in GUI thread. + + if (Thread.currentThread() != display.getThread()) { + display.syncExec(userInputGetter); + } else { + userInputGetter.run(); + } + + // Return loaded file data. + + File file = userInputGetter.getFile(); + AlgorithmFactory validator = userInputGetter.getValidator(); + + if ((file == null) || (validator == null)) { + String logMessage = "File loading canceled"; + this.logger.log(LogService.LOG_WARNING, logMessage); + + return null; + } else { + return FileValidator.validateFile(file, validator, this.ciShellContext, this.logger); + } + } + + public ProgressMonitor getProgressMonitor() { + return this.progressMonitor; + } + + public void setProgressMonitor(ProgressMonitor progressMonitor) { + this.progressMonitor = progressMonitor; + } + + private static String determineDefaultLoadDirectory(Dictionary<String, Object> preferences) { + return StringUtilities.emptyStringIfNull(preferences.get(LOAD_DIRECTORY_PREFERENCE_KEY)); + } + + private static IWorkbenchWindow getFirstWorkbenchWindow() throws AlgorithmExecutionException { + final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); + + if (windows.length == 0) { + throw new AlgorithmExecutionException( + "Cannot obtain workbench window needed to open dialog."); + } else { + return windows[0]; + } + } +} \ No newline at end of file Property changes on: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2010-05-28 18:18:24 UTC (rev 1067) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2010-05-28 18:53:00 UTC (rev 1068) @@ -12,19 +12,17 @@ import org.osgi.service.cm.ManagedService; import org.osgi.service.component.ComponentContext; -/* - * @author Weixia(Bonnie) Huang (hu...@in...) - */ public class FileLoadFactory implements AlgorithmFactory, ManagedService { - private BundleContext bcontext; + private BundleContext bundleContext; private Dictionary properties = new Hashtable(); - protected void activate(ComponentContext ctxt) { - bcontext = ctxt.getBundleContext(); + protected void activate(ComponentContext componentContext) { + bundleContext = componentContext.getBundleContext(); } - public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { - return new FileLoad(context, bcontext, properties); + public Algorithm createAlgorithm( + Data[] data, Dictionary parameters, CIShellContext ciShellContext) { + return new FileLoadAlgorithm(ciShellContext, this.bundleContext, this.properties); } public void updated(Dictionary properties) throws ConfigurationException { @@ -35,18 +33,18 @@ } // private void printPreferences(Dictionary properties) { -// System.out.println(" Preferences are as follows for File Load:"); -// if (properties == null) { -// System.out.println(" Dictionary is null!"); -// } else { -// Enumeration propertiesKeys = properties.keys(); +// System.out.println(" Preferences are as follows for File Load:"); +// if (properties == null) { +// System.out.println(" Dictionary is null!"); +// } else { +// Enumeration propertiesKeys = properties.keys(); +// +// while (propertiesKeys.hasMoreElements()) { +// String propertiesKey = (String) propertiesKeys.nextElement(); // -// while (propertiesKeys.hasMoreElements()) { -// String propertiesKey = (String) propertiesKeys.nextElement(); -// -// Object propertiesValue = properties.get(propertiesKey); -// System.out.println(" " + propertiesKey + ":" + propertiesValue); -// } +// Object propertiesValue = properties.get(propertiesKey); +// System.out.println(" " + propertiesKey + ":" + propertiesValue); // } // } +// } } \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadUserInputRunnable.java 2010-05-28 18:53:00 UTC (rev 1068) @@ -0,0 +1,147 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.utilities.FileUtilities; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.osgi.framework.BundleContext; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + +public final class FileLoadUserInputRunnable implements Runnable { + private IWorkbenchWindow window; + private BundleContext bundleContext; + private CIShellContext ciShellContext; + private File file; + private AlgorithmFactory validator; + + public FileLoadUserInputRunnable( + IWorkbenchWindow window, BundleContext bundleContext, CIShellContext ciShellContext) { + this.window = window; + this.bundleContext = bundleContext; + this.ciShellContext = ciShellContext; + } + + public File getFile() { + return this.file; + } + + public AlgorithmFactory getValidator() { + return this.validator; + } + + public void run() { + this.file = getFileFromUser(); + + if (file == null) { + return; + } else if (this.file.isDirectory()) { + FileLoadAlgorithm.defaultLoadDirectory = this.file.getAbsolutePath(); + } else { + FileLoadAlgorithm.defaultLoadDirectory = this.file.getParentFile().getAbsolutePath(); + } + + // Validate the loaded file, "casting" it to a certain MIME type. + + // Extract the file's file extension. + + String fileExtension = + FileUtilities.getFileExtension(this.file).toLowerCase().substring(1); + + // TODO split here? + + // Get all the validators which support this file extension... + + ServiceReference[] supportingValidators = getSupportingValidators(fileExtension); + + // If there are no supporting validators... + if (supportingValidators.length == 0) { + // Let the user choose from all the validators available. + + ServiceReference[] allValidators = getAllValidators(); + + FileFormatSelector validatorSelector = new FileFormatSelector( + "Load", window.getShell(), this.bundleContext, allValidators); + validatorSelector.open(); + this.validator = validatorSelector.getValidator(); + } else if (supportingValidators.length == 1) { + ServiceReference onlyPossibleValidator = supportingValidators[0]; + this.validator = + (AlgorithmFactory)this.bundleContext.getService(onlyPossibleValidator); + } + + if (supportingValidators.length > 1) { + FileFormatSelector validatorSelector = new FileFormatSelector( + "Load", window.getShell(), this.bundleContext, supportingValidators); + validatorSelector.open(); + this.validator = validatorSelector.getValidator(); + } + } + + private File getFileFromUser() { + FileDialog fileDialog = createFileDialog(); + String fileName = fileDialog.open(); + + if (fileName == null) { + return null; + } else { + return new File(fileName); + } + } + + private FileDialog createFileDialog() { + File currentDirectory = new File(FileLoadAlgorithm.defaultLoadDirectory); + String absolutePath = currentDirectory.getAbsolutePath(); + FileDialog fileDialog = new FileDialog(this.window.getShell(), SWT.OPEN); + fileDialog.setFilterPath(absolutePath); + fileDialog.setText("Select a File"); + + return fileDialog; + } + + private ServiceReference[] getSupportingValidators(String fileExtension) { + try { + String validatorsQuery = + "(& (type=validator)" + + "(|" + + "(in_data=file-ext:" + fileExtension + ")" + + "(also_validates=" + fileExtension + ")" + + "))"; + + ServiceReference[] supportingValidators = this.bundleContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), validatorsQuery); + + if (supportingValidators == null) { + return new ServiceReference[0]; + } else { + return supportingValidators; + } + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + + return new ServiceReference[]{}; + } + } + + private ServiceReference[] getAllValidators() { + try { + String validatorsQuery = "(&(type=validator)(in_data=file-ext:*))"; + ServiceReference[] allValidators = this.bundleContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), validatorsQuery); + + if (allValidators == null) { + return new ServiceReference[0]; + } else { + return allValidators; + } + } catch (InvalidSyntaxException e) { + e.printStackTrace(); + + return new ServiceReference[0]; + } + } +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileValidator.java 2010-05-28 18:53:00 UTC (rev 1068) @@ -0,0 +1,36 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmExecutionException; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.data.BasicData; +import org.cishell.framework.data.Data; +import org.osgi.service.log.LogService; + +public final class FileValidator { + public static Data[] validateFile( + File file, + AlgorithmFactory validator, + CIShellContext ciShellContext, + LogService logger) throws AlgorithmExecutionException { + Data[] validationData = + new Data[] { new BasicData(file.getPath(), String.class.getName()) }; + Data[] validatedData = validator.createAlgorithm( + validationData, null, ciShellContext).execute(); + + if (validatedData != null) { + logger.log(LogService.LOG_INFO, "Loaded: " + file.getPath()); + } + + return validatedData; +// } catch (AlgorithmExecutionException e) { +// String logMessage = +// "An error occurred while attempting to load your file " + +// "with the format you chose."; +// this.logger.log(LogService.LOG_ERROR, logMessage, e); +// this.thrownException = e; +// } + } +} \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java 2010-05-28 18:18:24 UTC (rev 1067) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java 2010-05-28 18:53:00 UTC (rev 1068) @@ -69,13 +69,8 @@ programCsv = Program.findProgram("csv"); }}); - - //TODO: what the hell? - System.err.println(definition.getID()); String[] defValStringArray = null; //doesn't actually work yet... - //String[] myOptionLabels = new String[] {programTxt.getName(),programDoc.getName(),programHtml.getName()}; - //String[] myOptionValues = new String[] {"txt","doc","html"}; int possiblePrograms = 0; int counter = 0; 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...> - 2011-02-08 17:58:40
|
Revision: 1198 http://cishell.svn.sourceforge.net/cishell/?rev=1198&view=rev Author: pataphil Date: 2011-02-08 17:58:33 +0000 (Tue, 08 Feb 2011) Log Message: ----------- * Removed FileLoaderAlgorithm and things its dependents. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/META-INF/MANIFEST.MF 2011-02-08 17:58:33 UTC (rev 1198) @@ -7,6 +7,7 @@ Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime Import-Package: org.cishell.app.service.datamanager;version="1.0.0", + org.cishell.app.service.fileloader, org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data;version="1.0.0", 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 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2011-02-08 17:58:33 UTC (rev 1198) @@ -26,15 +26,18 @@ import org.cishell.app.service.datamanager.DataManagerListener; import org.cishell.app.service.datamanager.DataManagerService; +import org.cishell.app.service.fileloader.FileLoaderService; +import org.cishell.framework.CIShellContext; +import org.cishell.framework.CIShellContextDelegate; import org.cishell.framework.LocalCIShellContext; +import org.cishell.framework.ServiceReferenceDelegate; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.data.BasicData; +import org.cishell.framework.algorithm.ProgressMonitor; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; import org.cishell.reference.gui.workspace.CIShellApplication; -import org.cishell.utilities.AlgorithmUtilities; import org.cishell.utilities.StringUtilities; import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.IMenuManager; @@ -198,6 +201,10 @@ getSite().setSelectionProvider(new DataModelSelectionProvider()); + setupDataManagerViewForDragAndDrop(parent); + } + + private void setupDataManagerViewForDragAndDrop(Composite parent) { DropTarget dropTarget = new DropTarget(parent.getParent(), DND.DROP_DEFAULT | DND.DROP_MOVE); dropTarget.setTransfer(new Transfer[] { FileTransfer.getInstance() }); @@ -211,37 +218,55 @@ fileNames = (String[]) event.data; Collection<File> flattenedFileStructure = flattenDraggedFileStructures(fileNames); - Collection<Data> dataForProcessing = new ArrayList<Data>(); - for (File file : flattenedFileStructure) { - dataForProcessing.add(new BasicData(file, "")); - } - - AlgorithmFactory fileLoaderFactory = - AlgorithmUtilities.getAlgorithmFactoryByPID( - "org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm", - Activator.context); + ServiceReference fileLoaderServiceReference = + Activator.context.getServiceReference(FileLoaderService.class.getName()); + FileLoaderService fileLoader = + (FileLoaderService) Activator.context.getService( + fileLoaderServiceReference); DataManagerService dataManager = (DataManagerService) Activator.context.getService( Activator.context.getServiceReference( DataManagerService.class.getName())); - try { - Data[] inputData = fileLoaderFactory.createAlgorithm( - dataForProcessing.toArray(new Data[0]), - new Hashtable<String, Object>(), - new LocalCIShellContext(Activator.context)).execute(); + ServiceReference dataManagerServiceReference = + Activator.context.getServiceReference(DataManagerService.class.getName()); - for (Data inputDatum : inputData) { - dataManager.addData(inputDatum); + for (File file : flattenedFileStructure) { + /* TODO: Eventually use the AlgorithmInvocationService for this + * kind of stuff? + */ + ServiceReference uniqueServiceReference = new ServiceReferenceDelegate( + dataManagerServiceReference); + CIShellContext ciShellContext = new CIShellContextDelegate( + uniqueServiceReference, new LocalCIShellContext(Activator.context)); + LogService uniqueLogger = + (LogService) ciShellContext.getService(LogService.class.getName()); + + try { + Data[] inputData = fileLoader.loadFile( + Activator.context, + ciShellContext, + uniqueLogger, + ProgressMonitor.NULL_MONITOR, + file); + + for (Data inputDatum : inputData) { + inputDatum.getMetadata().put( + DataProperty.SERVICE_REFERENCE, uniqueServiceReference); + dataManager.addData(inputDatum); + } + } catch (Throwable e) { + String format = + "An error occurred when loading your files.%n" + + "Please include the following when reporting this:%n%s"; + String logMessage = + String.format(format, StringUtilities.getStackTraceAsString(e)); + /* TODO: This is a spot where we might need to use a different + * LogService object (for when we want log highlighting). + */ + uniqueLogger.log(LogService.LOG_ERROR, logMessage); } - } catch (Throwable e) { - String format = - "An error occurred when loading your files.%n" + - "Please include the following when reporting this:%n%s"; - String logMessage = - String.format(format, StringUtilities.getStackTraceAsString(e)); - AbstractDataManagerView.this.logger.log(LogService.LOG_ERROR, logMessage); } } } Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2011-02-08 17:58:33 UTC (rev 1198) @@ -24,7 +24,7 @@ org.osgi.service.metatype;version="1.1.0", org.osgi.service.prefs;version="1.1.0" X-AutoStart: true -Service-Component: OSGI-INF/load.xml, OSGI-INF/save.xml, OSGI-INF/view.xml, OSGI-INF/viewwith.xml, OSGI-INF/fileloader.xml +Service-Component: OSGI-INF/load.xml, OSGI-INF/save.xml, OSGI-INF/view.xml, OSGI-INF/viewwith.xml Require-Bundle: org.eclipse.swt, org.eclipse.ui Bundle-RequiredExecutionEnvironment: J2SE-1.5 Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.properties 2011-02-08 17:58:33 UTC (rev 1198) @@ -1,8 +0,0 @@ -#menu_path=File/start -label=File Loader -description=This does the actual loading of files from the file system and loads them to Data Model window. -in_data=null -out_data=java.lang.Object -service.pid=org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm -remoteable=true -documentation_url=http://wiki.slis.indiana.edu:8080/display/ALGDOC/Data+Formats \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/fileloader.xml 2011-02-08 17:58:33 UTC (rev 1198) @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<component name="org.cishell.reference.gui.persistence.load.FileLoaderAlgorithm.component" immediate="false"> - <implementation class="org.cishell.reference.gui.persistence.load.FileLoaderAlgorithmFactory"/> - <properties entry="OSGI-INF/fileloader.properties"/> - <reference name="LOG" interface="org.osgi.service.log.LogService"/> - <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/> - - <service> - <provide interface="org.cishell.framework.algorithm.AlgorithmFactory"/> - </service> -</component> \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadAlgorithm.java 2011-02-08 17:58:33 UTC (rev 1198) @@ -52,31 +52,6 @@ } catch (FileLoadException e) { throw new AlgorithmExecutionException(e.getMessage(), e); } -// IWorkbenchWindow window = getFirstWorkbenchWindow(); -// Display display = PlatformUI.getWorkbench().getDisplay(); -// File[] files = getFilesToLoadFromUser(window, display); -// -// if (files != null) { -//// try { -// return new FileLoaderAlgorithm( -// this.bundleContext, -// files, -// this.ciShellContext, -// this.logger, -// this.progressMonitor).execute(); -//// } catch (Throwable e) { -//// String format = -//// "The chosen file is not compatible with this format. " + -//// "Check that your file is correctly formatted or try another validator. " + -//// "The reason is: %s"; -//// String logMessage = String.format(format, e.getMessage()); -//// this.logger.log(LogService.LOG_ERROR, logMessage, e); -//// -//// return null; -//// } -// } else { -// return null; -// } } public ProgressMonitor getProgressMonitor() { Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithm.java 2011-02-08 17:58:33 UTC (rev 1198) @@ -1,131 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Collection; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.AlgorithmExecutionException; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.algorithm.ProgressMonitor; -import org.cishell.framework.data.Data; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.osgi.framework.BundleContext; -import org.osgi.service.log.LogService; - -public class FileLoaderAlgorithm implements Algorithm { - private BundleContext bundleContext; - private File[] filesToLoad; - private CIShellContext ciShellContext; - private LogService logger; - private ProgressMonitor progressMonitor; - - public FileLoaderAlgorithm( - BundleContext bundleContext, - File[] filesToLoad, - CIShellContext ciShellContext, - LogService logger, - ProgressMonitor progressMonitor) { - this.bundleContext = bundleContext; - this.filesToLoad = filesToLoad; - this.ciShellContext = ciShellContext; - this.logger = logger; - this.progressMonitor = progressMonitor; - } - - public Data[] execute() throws AlgorithmExecutionException { - IWorkbenchWindow window = getFirstWorkbenchWindow(); - Display display = PlatformUI.getWorkbench().getDisplay(); - - if ((this.filesToLoad != null) && (this.filesToLoad.length != 0)) { - Collection<Data> finalLabeledFileData = new ArrayList<Data>(); - - for (File file : this.filesToLoad) { - try { - Data[] validatedFileData = validateFile(window, display, file); - Data[] labeledFileData = labelFileData(file, validatedFileData); - - for (Data data : labeledFileData) { - finalLabeledFileData.add(data); - } - } catch (Throwable e) { - String format = - "The chosen file is not compatible with this format. " + - "Check that your file is correctly formatted or try another validator. " + - "The reason is: %s"; - String logMessage = String.format(format, e.getMessage()); - this.logger.log(LogService.LOG_ERROR, logMessage, e); - } - } - - return finalLabeledFileData.toArray(new Data[0]); - } else { - return null; - } - } - - private IWorkbenchWindow getFirstWorkbenchWindow() throws AlgorithmExecutionException { - final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - - if (windows.length == 0) { - throw new AlgorithmExecutionException( - "Cannot obtain workbench window needed to open dialog."); - } else { - return windows[0]; - } - } - - private Data[] validateFile(IWorkbenchWindow window, Display display, File file) - throws AlgorithmExecutionException { - AlgorithmFactory validator = null; - validator = getValidatorFromUser(window, display, file); - - if ((file == null) || (validator == null)) { - String logMessage = "File loading canceled"; - this.logger.log(LogService.LOG_WARNING, logMessage); - } else { - try { - return FileValidator.validateFile( - file, validator, this.progressMonitor, this.ciShellContext, this.logger); - } catch (AlgorithmExecutionException e) { - if ((e.getCause() != null) - && (e.getCause() instanceof UnsupportedEncodingException)) { - String format = - "This file cannot be loaded; it uses the unsupported character " + - "encoding %s."; - String logMessage = String.format(format, e.getCause().getMessage()); - this.logger.log(LogService.LOG_ERROR, logMessage); - } else { - throw e; - } - } - } - - return new Data[0]; - } - - private Data[] labelFileData(File file, Data[] validatedFileData) { - Data[] labeledFileData = - PrettyLabeler.relabelWithFileNameHierarchy(validatedFileData, file); - - return labeledFileData; - } - - private AlgorithmFactory getValidatorFromUser( - IWorkbenchWindow window, Display display, File file) { - ValidatorSelectorRunnable validatorSelector = - new ValidatorSelectorRunnable(window, this.bundleContext, file); - - if (Thread.currentThread() != display.getThread()) { - display.syncExec(validatorSelector); - } else { - validatorSelector.run(); - } - - return validatorSelector.getValidator(); - } -} \ No newline at end of file Deleted: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java 2011-02-08 17:27:54 UTC (rev 1197) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoaderAlgorithmFactory.java 2011-02-08 17:58:33 UTC (rev 1198) @@ -1,40 +0,0 @@ -package org.cishell.reference.gui.persistence.load; - -import java.io.File; -import java.util.Dictionary; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.algorithm.ProgressMonitor; -import org.cishell.framework.data.Data; -import org.osgi.framework.BundleContext; -import org.osgi.service.component.ComponentContext; -import org.osgi.service.log.LogService; - -public class FileLoaderAlgorithmFactory implements AlgorithmFactory { - private BundleContext bundleContext; - private LogService logger; - - protected void activate(ComponentContext componentContext) { - this.bundleContext = componentContext.getBundleContext(); - this.logger = (LogService) this.bundleContext.getService( - this.bundleContext.getServiceReference(LogService.class.getName())); - } - - public Algorithm createAlgorithm( - Data[] data, Dictionary<String, Object> parameters, CIShellContext ciShellContext) { - File[] filesToLoad = new File[data.length]; - - for (int ii = 0; ii < data.length; ii++) { - filesToLoad[ii] = (File) data[ii].getData(); - } - - return new FileLoaderAlgorithm( - this.bundleContext, - filesToLoad, - ciShellContext, - this.logger, - ProgressMonitor.NULL_MONITOR); - } -} \ 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...> - 2011-02-16 17:40:52
|
Revision: 1210 http://cishell.svn.sourceforge.net/cishell/?rev=1210&view=rev Author: pataphil Date: 2011-02-16 17:40:45 +0000 (Wed, 16 Feb 2011) Log Message: ----------- * Trying to fix the build. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java trunk/clients/gui/org.cishell.reference.gui.workspace/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common/AbstractDialog.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common/ Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/common/ Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2011-02-16 16:36:46 UTC (rev 1209) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileFormatSelector.java 2011-02-16 17:40:45 UTC (rev 1210) @@ -9,7 +9,7 @@ import java.io.File; import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.reference.gui.common.AbstractDialog; +import org.cishell.reference.gui.workspace.common.AbstractDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; Modified: trunk/clients/gui/org.cishell.reference.gui.workspace/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.workspace/META-INF/MANIFEST.MF 2011-02-16 16:36:46 UTC (rev 1209) +++ trunk/clients/gui/org.cishell.reference.gui.workspace/META-INF/MANIFEST.MF 2011-02-16 17:40:45 UTC (rev 1210) @@ -8,7 +8,7 @@ org.eclipse.core.runtime, org.eclipse.update.ui Eclipse-LazyStart: true -Export-Package: org.cishell.reference.gui.common, - org.cishell.reference.gui.workspace +Export-Package: org.cishell.reference.gui.workspace, + org.cishell.reference.gui.workspace.common Import-Package: org.cishell.reference.gui.guibuilder.swt, org.cishell.service.guibuilder Property changes on: trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common ___________________________________________________________________ Added: svn:mergeinfo + Modified: trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common/AbstractDialog.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/common/AbstractDialog.java 2011-01-10 02:34:09 UTC (rev 1190) +++ trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common/AbstractDialog.java 2011-02-16 17:40:45 UTC (rev 1210) @@ -4,7 +4,7 @@ * * Created on Feb 22, 2005 at Indiana University. */ -package org.cishell.reference.gui.common; +package org.cishell.reference.gui.workspace.common; import org.eclipse.swt.SWT; import org.eclipse.swt.events.PaintEvent; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2011-02-18 15:25:59
|
Revision: 1221 http://cishell.svn.sourceforge.net/cishell/?rev=1221&view=rev Author: pataphil Date: 2011-02-18 15:25:52 +0000 (Fri, 18 Feb 2011) Log Message: ----------- * Trying to fix the build. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java trunk/clients/gui/org.cishell.reference.gui.workspace/META-INF/MANIFEST.MF Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common/AbstractDialog.java Modified: trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/MANIFEST.MF 2011-02-18 05:13:14 UTC (rev 1220) +++ trunk/clients/gui/org.cishell.reference.gui.guibuilder.swt/META-INF/MANIFEST.MF 2011-02-18 15:25:52 UTC (rev 1221) @@ -10,4 +10,6 @@ org.osgi.framework;version="1.3.0", org.osgi.service.metatype;version="1.1.0" Require-Bundle: org.eclipse.swt -Export-Package: org.cishell.reference.gui.guibuilder.swt +Export-Package: org.cishell.reference.gui.guibuilder.swt, + org.cishell.reference.gui.guibuilder.swt.builder, + org.cishell.reference.gui.guibuilder.swt.builder.components Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2011-02-18 05:13:14 UTC (rev 1220) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2011-02-18 15:25:52 UTC (rev 1221) @@ -9,7 +9,9 @@ org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data;version="1.0.0", - org.cishell.reference.gui.workspace.common, + org.cishell.reference.gui.guibuilder.swt, + org.cishell.reference.gui.guibuilder.swt.builder, + org.cishell.reference.gui.guibuilder.swt.builder.components, org.cishell.reference.service.conversion, org.cishell.reference.service.metatype, org.cishell.service.conversion;version="1.0.0", Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2011-02-18 05:13:14 UTC (rev 1220) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2011-02-18 15:25:52 UTC (rev 1221) @@ -16,7 +16,7 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.data.Data; -import org.cishell.reference.gui.workspace.common.AbstractDialog; +import org.cishell.reference.gui.guibuilder.swt.builder.AbstractDialog; import org.cishell.service.conversion.Converter; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; Modified: trunk/clients/gui/org.cishell.reference.gui.workspace/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.workspace/META-INF/MANIFEST.MF 2011-02-18 05:13:14 UTC (rev 1220) +++ trunk/clients/gui/org.cishell.reference.gui.workspace/META-INF/MANIFEST.MF 2011-02-18 15:25:52 UTC (rev 1221) @@ -8,7 +8,6 @@ org.eclipse.core.runtime, org.eclipse.update.ui Eclipse-LazyStart: true -Export-Package: org.cishell.reference.gui.workspace, - org.cishell.reference.gui.workspace.common +Export-Package: org.cishell.reference.gui.workspace Import-Package: org.cishell.reference.gui.guibuilder.swt, org.cishell.service.guibuilder Deleted: trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common/AbstractDialog.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common/AbstractDialog.java 2011-02-18 05:13:14 UTC (rev 1220) +++ trunk/clients/gui/org.cishell.reference.gui.workspace/src/org/cishell/reference/gui/workspace/common/AbstractDialog.java 2011-02-18 15:25:52 UTC (rev 1221) @@ -1,465 +0,0 @@ -/* - * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research - * and Education in Information Visualization (http://iv.slis.indiana.edu/). - * - * Created on Feb 22, 2005 at Indiana University. - */ -package org.cishell.reference.gui.workspace.common; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.ShellAdapter; -import org.eclipse.swt.events.ShellEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Canvas; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Dialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - - -/** - * This class provides a DialogBox structure that can be extended to create Dialogs for CIShell. - * This framework will enforce consistency in the look and feel of Dialogs in CIShell by providing a - * standard layout of description, content, and buttons[, along with a choice of icon images - * defined as constants in this class]. An optional details section allows the Dialog designer - * to provide additional information when the details button is pressed. - * - * @author Team IVC - */ -public abstract class AbstractDialog extends Dialog { - public static final Image INFORMATION = Display.getCurrent().getSystemImage(SWT.ICON_INFORMATION); - public static final Image WARNING = Display.getCurrent().getSystemImage(SWT.ICON_WARNING); - public static final Image ERROR = Display.getCurrent().getSystemImage(SWT.ICON_ERROR); - public static final Image QUESTION = Display.getCurrent().getSystemImage(SWT.ICON_QUESTION); - public static final Image WORKING = Display.getCurrent().getSystemImage(SWT.ICON_WORKING); - -// private static final Image ivcIcon = IVCImageLoader.createImage("ivc.gif"); - - //constants used in resizing of shell when details are shown/hidden - private static final int DETAILS_HEIGHT = 75; - private static final int SCROLLBAR_BUFFER = 47; - - - private String description = ""; - private String detailsString = ""; - private Text detailsText; - private Shell shell; - private Image image; - private boolean success; - private Composite header; - private Composite content; - private Composite buttons; - private Shell parent; - - /** - * Creates a new AbstractDialog object. - * - * @param parent the parent Shell of this AbstractDialog - * @param title the title to put in the title bar of this AbstractDialog - * @param image the Image to display to the left of the description specified - * for this AbstractDialog. This will usually be one of: - * <ul> - * <li>AbstractDialog.WARNING</li> - * <li>AbstractDialog.INFORMATION</li> - * <li>AbstractDialog.ERROR</li> - * <li>AbstractDialog.WORKING</li> - * <li>AbstractDialog.QUESTION</li> - * </ul> - */ - public AbstractDialog(Shell parent, String title, Image image) { - super(parent, 0); - setText(title); - this.image = image; - this.parent = parent; - init(); - } - - /** - * Closes this AbstractDialog. - * - * @param success true if the dialog was successful, false if it - * was cancelled by the user (or closed prematurely) - */ - public void close(boolean success){ - shell.dispose(); - this.success = success; - } - - /** - * Returns the shell used by this AbstractDialog - * - * @return the shell used by this AbstractDialog - */ - public Shell getShell(){ - return shell; - } - - /** - * Initializes this AbstractDialog. This consists of resetting all of the - * customizable components like the content area, details pane, buttons, - * and description label, and readying the dialog to be refilled with - * new content. - */ - public void init(){ - if(shell != null) - shell.dispose(); - - shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL); - shell.setText(getText()); -// shell.setImage(ivcIcon); - GridLayout layout = new GridLayout(); - layout.numColumns = 1; - shell.setLayout(layout); - } - - /** - * Opens this AbstractDialog. - * - * @return true if this AbstractDialog was closed by clicking the 'x' in the upper right - * corner of the window, signifying a cancellation, false if the dialog is exited otherwise. - */ - public boolean open() { - success = true; - - setupHeader(); - setupContent(); - setupButtons(); - - shell.pack(); - setLocation(); - shell.open(); - shell.addShellListener(new ShellAdapter(){ - public void shellClosed(ShellEvent e) { - success = false; - } - }); - Display display = getParent().getDisplay(); - - while (!shell.isDisposed()) { - if (!display.readAndDispatch()) { - display.sleep(); - } - } - - return success; - } - - /* - * centers the dialog on its parents shell - */ - private void setLocation(){ - Point parentLocation = parent.getLocation(); - int parentWidth = parent.getSize().x; - int parentHeight = parent.getSize().y; - int shellWidth = shell.getSize().x; - int shellHeight = shell.getSize().y; - - int x = parentLocation.x + (parentWidth - shellWidth)/2; - int y = parentLocation.y + (parentHeight - shellHeight)/2; - shell.setLocation(x, y); - - } - - /** - * Sets the Description of this AbstractDialog. This is the text that is displayed in the - * top section of the Dialog window, giving information about the question that is being - * asked or the information that is being given. - * - * @param description the description for this AbstractDialog to use - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Sets the details text of this AbstractDialog. This is the text that is displayed in the lower - * section of the Dialog window when the user presses the "Details >>" button. If this String - * is null or the empty string, the details button will be disabled. - * - * @param details DOCUMENT ME! - */ - public void setDetails(String details) { - this.detailsString = details; - } - - /** - * Creates the Buttons to use in this AbstractDialog based on the given parent. These are - * the buttons that show up at the bottom of the dialog for user input, such as a - * "Yes/No" group or "Continue/Cancel" or something like that. This does not encompass all - * Buttons created in the dialog (such as those created in the content section), just those - * to display at the bottom of the dialog. - * - * @param parent the parent to be used to create the Buttons for this AbstractDialog - */ - public abstract void createDialogButtons(Composite parent); - - /** - * Creates the content section of this AbstractDialog based on the given parent. - * This section is where all of the "guts" of the AbstractDialog go, specifying the controls - * that are needed to interact with the user and provide whatever questions or information - * are needed. - * - * @param parent the parent to be used to create the Buttosn for this AbstractDialog - * - * @return the Composite that is created to display the content of this AbstractDialog - */ - public abstract Composite createContent(Composite parent); - - /* - * Sets up the header section of the dialog. This section contains the image for the - * type of dialog it is, as well as the description label - */ - private void setupHeader() { - header = new Composite(shell, SWT.NONE); - header.setLayoutData(new GridData(GridData.FILL_BOTH)); - GridLayout layout = new GridLayout(); - layout.numColumns = 2; - header.setLayout(layout); - - Canvas canvas = new Canvas(header, SWT.NONE); - if (image != null) { - canvas.addPaintListener(new PaintListener() { - public void paintControl(PaintEvent e) { - e.gc.drawImage(image, 0, 0); - } - }); - } - GridData canvasData = new GridData(); - canvasData.heightHint = image.getBounds().height; - canvas.setLayoutData(canvasData); - - - Label desc = new Label(header, SWT.WRAP); - - if ((description != null) && !description.equals("")) { - desc.setText(description); - } - - GridData data = new GridData(GridData.FILL_BOTH | GridData.VERTICAL_ALIGN_CENTER); - data.widthHint = 300; - desc.setLayoutData(data); - } - - /* - * sets up the content section of the dialog, this calls the abstract method to - * create the content that must be implemented by all subclasses - */ - private void setupContent() { - content = createContent(shell); - - if (content != null) { - content.setLayoutData(new GridData(GridData.FILL_BOTH)); - } - } - - /* - * sets up the button section in the bottom of the dialog. These buttons - * are created in the abstract method createDialogButtons(parent). In addition to - * any created buttons, a "Details >>" button is added to allow the user to see any - * details that are available in the current Dialog. - */ - private void setupButtons() { - buttons = new Composite(shell, SWT.NONE); - buttons.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_END)); - - //there are two sections, all the user stuff to the left, and - //then the details button on the far right - //User Buttons Section - createDialogButtons(buttons); - Control[] controls = buttons.getChildren(); - GridLayout buttonsLayout = new GridLayout(); - buttonsLayout.numColumns = controls.length + 1; - buttonsLayout.makeColumnsEqualWidth = true; - buttons.setLayout(buttonsLayout); - - //setup the grid data for each button for standard look - for (int i = 0; i < controls.length; i++) { - controls[i].setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - } - - //Details Button section - Button details = new Button(buttons, SWT.PUSH); - details.setText("Details >>"); - details.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - details.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if ((detailsText == null) || detailsText.isDisposed()) { - //show details section - setupDetails(); - shell.pack(); - } else { - //remove details section - detailsText.dispose(); - shell.pack(); - } - } - }); - details.setEnabled((detailsString != null) && - !detailsString.equals("")); - } - - /* - * creates the details text box when the "Details >>" button is toggled - */ - private void setupDetails() { - int width = shell.getSize().x; - detailsText = new Text(shell, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL); - detailsText.setEditable(false); - detailsText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE)); - - GridData data = new GridData(); - data.grabExcessHorizontalSpace = false; - data.grabExcessVerticalSpace = false; - data.widthHint = width - SCROLLBAR_BUFFER; - data.heightHint = DETAILS_HEIGHT; - detailsText.setLayoutData(data); - if(detailsString != null) - detailsText.setText(detailsString); - } - - /** - * Open a standard error dialog with OK button - * - * @param parent the parent Shell of this dialog - * @param title the text to display in the title bar of this dialog - * @param message the message to give in the dialog's body - * @param details the text to put in the details pane to be visible when the - * "Details >>" button is pressed (can be null or empty, resulting - * in the "Details >>" button not being enabled) - * @return true if the dialog was exited by pressing the OK button, false - * if it was cancelled by pressing the 'x' in the title bar - */ - public static boolean openError(Shell parent, String title, String message, String details){ - return openOKDialog(parent, ERROR, title, message, details); - } - - /** - * Open a standard information dialog with OK button - * - * @param parent the parent Shell of this dialog - * @param title the text to display in the title bar of this dialog - * @param message the message to give in the dialog's body - * @param details the text to put in the details pane to be visible when the - * "Details >>" button is pressed (can be null or empty, resulting - * in the "Details >>" button not being enabled) * @return true if the dialog was exited by pressing the OK button, false - * if it was cancelled by pressing the 'x' in the title bar - */ - public static boolean openInformation(Shell parent, String title, String message, String details){ - return openOKDialog(parent, INFORMATION, title, message, details); - } - - /** - * Open a standard warning dialog with OK button - * - * @param parent the parent Shell of this dialog - * @param title the text to display in the title bar of this dialog - * @param message the message to give in the dialog's body - * @param details the text to put in the details pane to be visible when the - * "Details >>" button is pressed (can be null or empty, resulting - * in the "Details >>" button not being enabled) * @return true if the dialog was exited by pressing the OK button, false - * if it was cancelled by pressing the 'x' in the title bar - */ - public static boolean openWarning(Shell parent, String title, String message, String details){ - return openOKDialog(parent, WARNING, title, message, details); - } - - /** - * Open a standard question dialog with Yes/No buttons - * - * @param parent the parent Shell of this dialog - * @param title the text to display in the title bar of this dialog - * @param message the message to give in the dialog's body - * @param details the text to put in the details pane to be visible when the - * "Details >>" button is pressed (can be null or empty, resulting - * in the "Details >>" button not being enabled) * @return true if the dialog was exited by pressing the OK button, false - * if it was cancelled by pressing the 'x' in the title bar or pressing the - * No button - */ - public static boolean openQuestion(Shell parent, String title, String message, String details){ - return openConfirmDenyDialog(parent, QUESTION, title, message, details, "Yes", "No"); - } - - /** - * Open a standard confirmation dialog with OK/Cancel buttons - * - * @param parent the parent Shell of this dialog - * @param title the text to display in the title bar of this dialog - * @param message the message to give in the dialog's body - * @param details the text to put in the details pane to be visible when the - * "Details >>" button is pressed (can be null or empty, resulting - * in the "Details >>" button not being enabled) * @return true if the dialog was exited by pressing the OK button, false - * if it was cancelled by pressing the 'x' in the title bar or pressing - * the Cancel button - */ - public static boolean openConfirm(Shell parent, String title, String message, String details){ - return openConfirmDenyDialog(parent, QUESTION, title, message, details, "OK", "Cancel"); - } - - /* - * helper to create OK dialogs: error, warning, information - */ - private static boolean openOKDialog(Shell parent, Image image, String title, String message, String details){ - AbstractDialog okDialog = new AbstractDialog(parent, title, image){ - public void createDialogButtons(Composite parent) { - Button ok = new Button(parent, SWT.PUSH); - ok.setText("OK"); - ok.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - close(true); - } - }); - } - - public Composite createContent(Composite parent) { - return null; - } - }; - okDialog.setDescription(message); - okDialog.setDetails(details); - return okDialog.open(); - } - - /* - * helper to create confirm/deny dialogs: question, confirmation - */ - private static boolean openConfirmDenyDialog(Shell parent, Image image, String title, String message, String details, final String confirmLabel, final String denyLabel){ - AbstractDialog dialog = new AbstractDialog(parent, title, image){ - public void createDialogButtons(Composite parent) { - Button confirm = new Button(parent, SWT.PUSH); - if(confirmLabel != null) - confirm.setText(confirmLabel); - confirm.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - close(true); - } - }); - Button deny = new Button(parent, SWT.PUSH); - if(denyLabel != null) - deny.setText(denyLabel); - deny.addSelectionListener(new SelectionAdapter(){ - public void widgetSelected(SelectionEvent e) { - close(false); - } - }); - } - - public Composite createContent(Composite parent) { - return null; - } - }; - dialog.setDescription(message); - dialog.setDetails(details); - return dialog.open(); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |