From: <bea...@us...> - 2006-10-03 19:20:28
|
Revision: 243 http://svn.sourceforge.net/cishell/?rev=243&view=rev Author: bearsfan Date: 2006-10-03 12:20:18 -0700 (Tue, 03 Oct 2006) Log Message: ----------- Added javadoc for all source files under the save package Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2006-10-02 19:25:15 UTC (rev 242) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2006-10-03 19:20:18 UTC (rev 243) @@ -19,34 +19,48 @@ import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; /** - * @author Team IVC + * Persist the file to disk for the user + * + * @author Team */ public class FileSaver { private static File currentDir; private Shell parent; - private LogService logService; - private CIShellContext ciContext; private GUIBuilderService guiBuilder; + /** + * Initializes services to output messages + * + * @param parent + * @param context + */ public FileSaver(Shell parent, CIShellContext context){ this.parent = parent; - this.ciContext = context; - this.logService = (LogService) ciContext.getService(LogService.class.getName()); this.guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); } + /** + * File exists, so make sure the user wants to overwrite + * @param file The file to possibly overwrite + * @return Whether or not the user decides to overwrite + */ private boolean confirmFileOverwrite(File file) { String message = "The file:\n" + file.getPath() + "\nalready exists. Are you sure you want to overwrite it?"; return guiBuilder.showConfirm("File Overwrite", message, ""); } + /** + * Checks for a valid file destination + * + * @param file to save to + * @return True on valid file save + */ private boolean isSaveFileValid(File file) { boolean valid = false; if (file.isDirectory()) { @@ -61,6 +75,13 @@ return valid; } + /** + * Given a converter, save the data + * + * @param converter Saves the data to a file + * @param data Data object to save + * @return Whether or not the save was successful + */ public boolean save(Converter converter, Data data) { ServiceReference[] serviceReferenceArray = converter.getConverterChain(); String outDataStr = (String)serviceReferenceArray[serviceReferenceArray.length-1] @@ -113,7 +134,9 @@ done = true; - logService.log(LogService.LOG_INFO, "Saved: " + selectedFile.getPath() + "\n"); + guiBuilder.showInformation("Data Saved", + "Data successfully saved to disk", + "Saved: " + selectedFile.getPath()); } else { done = true; return false; @@ -122,6 +145,13 @@ return true; } + /** + * Converter puts it into a temporary directory, this copies it over + * + * @param in The temp file to copy + * @param out Destination to copy to + * @return True on successful copy, false otherwise + */ private boolean copy(File in, File out) { try { FileInputStream fis = new FileInputStream(in); Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2006-10-02 19:25:15 UTC (rev 242) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2006-10-03 19:20:18 UTC (rev 243) @@ -11,6 +11,11 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; +/** + * Save algorithm for persisting a data object + * + * @author bmarkine + */ public class Save implements Algorithm { Data[] data; Dictionary parameters; @@ -20,8 +25,14 @@ private GUIBuilderService guiBuilder; private DataConversionService conversionManager; - //private LogService logService; + /** + * Sets up default services for the algorithm + * + * @param data The data array to persist + * @param parameters Parameters for the algorithm + * @param context Provides services to CIShell services + */ public Save(Data[] data, Dictionary parameters, CIShellContext context) { this.data = data; this.parameters = parameters; @@ -32,16 +43,19 @@ this.conversionManager = (DataConversionService) context.getService( DataConversionService.class.getName()); - //this.logService = (LogService)context.getService(LogService.class.getName()); this.guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); } + /** + * Executes the algorithm + * + * @return Null for this algorithm + */ public Data[] execute() { //This only checks the first Data in the array final Converter[] converters = conversionManager.findConverters(data[0], "file-ext:*"); if (converters.length < 1) { - //logService.log(LogService.LOG_ERROR, "No valid converters found!"); guiBuilder.showError("No Converters", "No valid converters for data type: " + data[0].getData().getClass().getName(), @@ -51,7 +65,6 @@ if (!parentShell.isDisposed()) { parentShell.getDisplay().syncExec(new Runnable() { public void run() { - //Shell shell = new Shell(parentShell); SaveDataChooser sdc = new SaveDataChooser(data[0], parentShell, converters, "title", 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 2006-10-02 19:25:15 UTC (rev 242) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2006-10-03 19:20:18 UTC (rev 243) @@ -32,13 +32,12 @@ import org.cishell.reference.gui.common.AbstractDialog; /** - * SavePersisterChooser is a simple user interface to allow for selection + * SaveDataChooser is a simple user interface to allow for selection * among several Persisters that support the selected model, in the event * that more than one is found. * * @author Team IVC */ -//public class SaveDataChooser extends Shell { public class SaveDataChooser extends AbstractDialog { protected Data data; protected Converter[] converterArray; @@ -49,31 +48,33 @@ public static final Image QUESTION = Display.getCurrent().getSystemImage(SWT.ICON_QUESTION); /** - * Creates a new SavePersisterChooser object. + * Creates a new SaveChooser object. * - * @param title the desired Title of the SavePersisterChooser window - * @param model the model that this SavePersisterChooser is attempting to save - * @param window the IWorkbenchWindow that this SavePersisterChooser belongs to - * @param persisters the Persisters that can be used to save the given model + * @param data The data object to save + * @param parent The parent shell + * @param converterArray The array of converters to persist the data + * @param title Title of the Window + * @param brandPluginID The plugin that supplies the branding + * @param context The CIShellContext to retrieve available services */ - //public SaveDataChooser(String title, Data data, Shell parent, Data[] converterArray) { public SaveDataChooser(Data data, Shell parent, Converter[] converterArray, String title, String brandPluginID, CIShellContext context) { super(parent, title, QUESTION); this.data = data; - //this.parent = parent; this.converterArray = converterArray; this.context = context; } - /* - * Initialize the GUI for this SavePersisterChooser + /** + * Initialize the GUI for the chooser + * @param parent The parent window + * @return The new window containing the chooser */ private Composite initGUI(Composite parent) { Composite content = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; - content.setLayout(layout); + content.setLayout(layout); //parent.setLayout(layout); Group converterGroup = new Group(content, SWT.NONE); @@ -97,7 +98,6 @@ }); Group detailsGroup = new Group(content, SWT.NONE); - //Group detailsGroup = new Group(parent, SWT.NONE); detailsGroup.setText("Details"); detailsGroup.setLayout(new FillLayout()); GridData detailsData = new GridData(GridData.FILL_BOTH); @@ -113,7 +113,7 @@ return content; } - /* + /** * Initialize the Listbox of Persisters using the stored Persister array */ private void initConverterList() { @@ -133,8 +133,10 @@ } } - /* - * Sets up the DetailPane where the details from the Persister PropertyMaps are displayed. + /** + * Sets up the DetailPane where the details from the Persister PropertyMaps are displayed. + * @param detailsGroup The detail pane to init + * @return A style of the text */ private StyledText initDetailPane(Group detailsGroup) { StyledText detailPane = new StyledText(detailsGroup, SWT.H_SCROLL | SWT.V_SCROLL); @@ -144,9 +146,10 @@ return detailPane; } - /* + /** * Changes the information displayed in the DetailsPane whenever a new Persister * is selected. + * @param converter A converter that contains the properties for the detail pane */ private void updateDetailPane(Converter converter) { Dictionary dict = converter.getProperties(); @@ -157,8 +160,6 @@ while (keysEnum.hasMoreElements()) { Object key = keysEnum.nextElement(); Object val = dict.get(key); - //if(property.getAcceptableClass().equals(String.class)){ - // String val = (String) dict.getPropertyValue(property); StyleRange styleRange = new StyleRange(); styleRange.start = detailPane.getText().length(); @@ -168,13 +169,13 @@ detailPane.setStyleRange(styleRange); detailPane.append(val + "\n"); - //} } } - /* + /** * When a Persister is chosen to Persist this model, this method handles the job * of opening the FileSaver and saving the model. + * @param selectedIndex The chosen converter */ protected void selectionMade(int selectedIndex) { getShell().setVisible(false); @@ -183,6 +184,12 @@ close(saver.save(converter, data)); } + /** + * Create the buttons for either cancelling or continuing with + * the save + * + * @param parent The GUI to place the buttons + */ public void createDialogButtons(Composite parent) { Button select = new Button(parent, SWT.PUSH); select.setText("Select"); @@ -205,6 +212,12 @@ }); } + /** + * Checks for the number of file savers. If there is one + * converter then it will save directly, otherwise intialize the chooser. + * + * @param parent The parent GUI for new dialog windows. + */ public Composite createContent(Composite parent) { if (converterArray.length == 1) { final FileSaver saver = new FileSaver((Shell)parent, context); Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2006-10-02 19:25:15 UTC (rev 242) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2006-10-03 19:20:18 UTC (rev 243) @@ -13,23 +13,54 @@ import org.osgi.service.component.ComponentContext; import org.osgi.service.metatype.MetaTypeProvider; - +/** + * Create a Save object + * @author bmarkine + * + */ public class SaveFactory implements AlgorithmFactory, DataValidator { private CIShellContext context; + /** + * Create a local CIShell context + * @param ctxt The current CIShell context + */ protected void activate(ComponentContext ctxt) { context = new LocalCIShellContext(ctxt.getBundleContext()); } + + /** + * Deactivate the plugin + * @param ctxt Current CIShell context + */ protected void deactivate(ComponentContext ctxt) {} + /** + * Create a Save algorithm + * @param data The data objects to save + * @param parameters The parameters for the algorithm + * @param context Reference to services provided by CIShell + * @return An instance of the Save algorithm + */ public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { this.context = context; return new Save(data, parameters, context); } + + /** + * Create parameters (this returns null only) + * data input data + * @return null; + */ public MetaTypeProvider createParameters(Data[] data) { return null; } + /** + * Validate the SaveFactory can handle the incoming file type + * @param data The data to save + * @return empty string on success + */ public String validate(Data[] data) { DataConversionService conversionManager = (DataConversionService) context.getService( DataConversionService.class.getName()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |