From: <hu...@us...> - 2006-09-28 19:11:54
|
Revision: 215 http://svn.sourceforge.net/cishell/?rev=215&view=rev Author: huangb Date: 2006-09-28 12:11:20 -0700 (Thu, 28 Sep 2006) Log Message: ----------- initial version Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath trunk/clients/gui/org.cishell.reference.gui.persistence/.project trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/ trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/l10n/ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/l10n/bundle_en.properties 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/ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml trunk/clients/gui/org.cishell.reference.gui.persistence/build.properties trunk/clients/gui/org.cishell.reference.gui.persistence/src/ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/ 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/FileLoadFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadPersisterChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/ 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 Added: trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="output" path="bin"/> +</classpath> Added: trunk/clients/gui/org.cishell.reference.gui.persistence/.project =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.project (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.project 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.cishell.reference.gui.persistence</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> Added: trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.pde.core.prefs 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,3 @@ +#Wed Sep 27 14:27:31 EDT 2006 +eclipse.preferences.version=1 +pluginProject.extensions=false Added: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Persistence Plug-in +Bundle-SymbolicName: org.cishell.reference.gui.persistence +Bundle-Version: 0.0.1 +Bundle-ClassPath: . +Bundle-Localization: plugin +Import-Package: org.cishell.app.service.datamanager, + org.cishell.framework, + org.cishell.framework.algorithm, + org.cishell.framework.data, + org.cishell.reference.gui.common, + org.cishell.service.conversion, + org.osgi.framework;version="1.3.0", + org.osgi.service.component;version="1.0.0", + org.osgi.service.log;version="1.3.0", + 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 +Require-Bundle: org.eclipse.swt, + org.eclipse.ui + Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/l10n/bundle_en.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/l10n/bundle_en.properties (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/l10n/bundle_en.properties 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,7 @@ +#Localization variables for OSGI-INF/metatatype/METADATA.XML +# +#Samples: +#input=Input +#desc=Enter an integer (that will be converted to a string) +#name=Input->String +#name_desc=Converts inputted integer to string Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,7 @@ +menu_path=file/additions/ +label=Load... +description=This converter 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 +remoteable=true Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<component name="org.cishell.reference.gui.persistence.load.FileLoad.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"/> + <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 Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"> + <OCD name="File Load Converter" id="org.cishell.reference.gui.load.FileLoad.OCD" + description=""> + </OCD> + <Designate pid="org.cishell.reference.gui.load.FileLoad"> + <Object ocdref="org.cishell.reference.gui.load.FileLoad.OCD" /> + </Designate> +</metatype:MetaData> Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,7 @@ +menu_path=File/Save +label=Save... +description=Saves data to disk +in_data=java.lang.Object +out_data=file:* +service.pid=org.cishell.reference.gui.persistence.save.Save +remoteable=false Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<component name="org.cishell.reference.gui.persistence.save.Save.component" immediate="false"> + <implementation class="org.cishell.reference.gui.persistence.save.SaveFactory"/> + <properties entry="OSGI-INF/save.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 Added: trunk/clients/gui/org.cishell.reference.gui.persistence/build.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/build.properties (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/build.properties 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,163 @@ +package org.cishell.reference.gui.persistence.load; + +import java.io.File; +import java.util.ArrayList; + +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; + + +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.log.LogService; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.data.Data; +import org.cishell.framework.data.BasicData; + +/* + * @author Weixia(Bonnie) Huang (hu...@in...) + */ +public class FileLoad implements Algorithm{ + + private static File currentDir; + private final LogService logger; + private final BundleContext bContext; + private CIShellContext ciContext; + + public FileLoad(CIShellContext ciContext, BundleContext bContext) { + this.ciContext = ciContext; + this.bContext = bContext; + logger = (LogService) ciContext.getService(LogService.class.getName()); + } + + public void selectionChanged(IAction action, ISelection selection) { + + } + + public Data[] execute() { +// int counter = PlatformUI.getWorkbench().getWorkbenchWindowCount(); +// System.out.println("counter is "+counter); +// ?? why getActiveWorkbenchWindow() didn't work?? + Data[] returnDM; + final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); + if (windows.length ==0){ + System.out.println("windows[0] is null!!"); + return null; + } + + Display display = PlatformUI.getWorkbench().getDisplay(); + DataUpdater dataUpdater = new DataUpdater (windows[0]); + display.syncExec(dataUpdater); + if (!dataUpdater.returnList.isEmpty()){ + int size = dataUpdater.returnList.size(); + returnDM = new Data[size]; + for(int index=0; index<size; index++){ + returnDM[index]=(Data)dataUpdater.returnList.get(index); + } + return returnDM; + } + else { +// logger.log(LogService.LOG_INFO, "Did not load any data..."); + return null; + } + + } + + public static String getFileExtension(File theFile) { + String fileName = theFile.getName() ; + String extension ; + if (fileName.lastIndexOf(".") != -1) + extension = fileName.substring(fileName.lastIndexOf(".")) ; + else + extension = "" ; + return extension ; + } + + final class DataUpdater implements Runnable{ + IWorkbenchWindow window; + ArrayList returnList = new ArrayList(); + + DataUpdater (IWorkbenchWindow window){ + this.window = window; + } + + public void run (){ + + FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN); + if (currentDir == null) { + currentDir = new File(System.getProperty("user.dir") + File.separator + "sampledata" + File.separator + "anything"); + } + dialog.setFilterPath(currentDir.getPath()); + dialog.setText("Select a File"); + String fileName = dialog.open(); + if (fileName == null) { + return; + } + + File file = new File(fileName); + + if (file.isDirectory()) { + currentDir = file; + } else { + currentDir = new File(file.getPath()); + } +// FileResourceDescriptor frd = new BasicFileResourceDescriptor(file); +// String fileExtension = frd.getFileExtension(); + + String fileExtension = getFileExtension(file); + System.out.println("fileExtension = "+fileExtension); + String filter = "(&(type=converter)(in_data=file-ext:"+fileExtension+"))"; + try { + + // set the properties for the resource descriptor. + // note that this relies on the fact that the compression is set + // to nocompression by default. + + // get all the service references of converters that can load this type of file. +// ServiceReference[] serviceRefList = bContext.getServiceReferences(null, filter); + ServiceReference[] serviceRefList = bContext.getAllServiceReferences( + AlgorithmFactory.class.getName(), filter); + + + // no converters found means the file format is not supported + if (serviceRefList == null || serviceRefList.length == 0){ + //log "The file format is not supported" + logger.log(LogService.LOG_INFO, "Sorry, the file format: *"+fileExtension+" is not supported so far."); + return; + } + + //<filename>[.<data model type>][.<index>] + // only one persister found, so load the model + if (serviceRefList.length == 1){ + logger.log(LogService.LOG_INFO, "Loaded: "+file.getPath()); + AlgorithmFactory persister = (AlgorithmFactory)bContext.getService(serviceRefList[0]); + Data[] dm = new Data[]{new BasicData(file.getPath(), String.class.getName()) }; + dm = persister.createAlgorithm(dm, null, ciContext).execute(); + for (int i=0; i<dm.length; i++) + returnList.add(dm[i]); + return; + + } + + // lots of persisters found, return the chooser + new LoadPersisterChooser("Load", file, window.getShell(), + ciContext, bContext, serviceRefList, returnList).open(); + + + }catch (Exception e){ + e.printStackTrace(); + } + + }//end run() + } //end class + + +} \ No newline at end of file Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,35 @@ +package org.cishell.reference.gui.persistence.load; + +//standard java +import java.util.Dictionary; + +//osgi +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.metatype.MetaTypeProvider; + +//cishell +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.data.Data; + +/* + * @author Weixia(Bonnie) Huang (hu...@in...) + */ +public class FileLoadFactory implements AlgorithmFactory { + private BundleContext bcontext; + + protected void activate(ComponentContext ctxt) { + bcontext = ctxt.getBundleContext(); + } + protected void deactivate(ComponentContext ctxt) {} + + public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { + return new FileLoad(context, bcontext); + } + public MetaTypeProvider createParameters(Data[] data) { + return null; + } + +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadPersisterChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadPersisterChooser.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/LoadPersisterChooser.java 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,201 @@ +/* + * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research + * and Education in Information Visualization (http://iv.slis.indiana.edu/). + * + * Created on Jan 24, 2005 at Indiana University. + */ +package org.cishell.reference.gui.persistence.load; + +import java.util.ArrayList; +import java.io.File; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; + +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.log.LogService; + +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.reference.gui.common.AbstractDialog; + +/** + * + * @author Team IVC (Weixia Huang, James Ellis) + */ +public class LoadPersisterChooser extends AbstractDialog { + private File theFile; + private LogService logger; + + private ServiceReference[] persisterArray; + private List persisterList; + private StyledText detailPane; + private CIShellContext ciContext; + private BundleContext bContext; + private ArrayList returnList; + + private static final String[] details_prop_names = + {"format_name", "supported_file_extension", "format_description", + "restorable_model_name", "restorable_model_description" }; + private static final String[] details_prop_name_descriptions = + {"Format name", "Supported file extension", "Format description", + "Restorable model name", "Restorable model description" }; + + public LoadPersisterChooser(String title, File theFile, + Shell parent, CIShellContext ciContext, BundleContext bContext, + ServiceReference[] persisterArray, ArrayList returnList){ + super(parent, title, AbstractDialog.QUESTION); + this.ciContext = ciContext; + this.bContext = bContext; + this.persisterArray = persisterArray; + this.returnList = returnList; + + this.theFile = theFile; + + this.logger = (LogService) ciContext.getService(LogService.class.getName()); +//shall this part be moved out of the code? + setDescription("The file you have selected can be loaded" + + " using the following formats.\n" + + "Please select one of them."); + setDetails("This dialog allows the user to choose among all available " + + "formats for loading the selected data model. Choose any of the formats " + + "to continue loading the dataset."); + } + + private Composite initGUI(Composite parent) { + Composite content = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + content.setLayout(layout); + + Group persisterGroup = new Group(content, SWT.NONE); +//shall this label be moved out of the code? + persisterGroup.setText("Loaded by"); + persisterGroup.setLayout(new FillLayout()); + GridData persisterListGridData = new GridData(GridData.FILL_BOTH); + persisterListGridData.widthHint = 200; + persisterGroup.setLayoutData(persisterListGridData); + + persisterList = new List(persisterGroup, SWT.H_SCROLL |SWT.V_SCROLL | SWT.SINGLE); +// initPersisterArray(); + initPersisterList(); + persisterList.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + List list = (List)e.getSource(); + int selection = list.getSelectionIndex(); + if(selection != -1){ + updateDetailPane(persisterArray[selection]); + } + } + }); + + Group detailsGroup = new Group(content, SWT.NONE); +// shall this label be moved out of the code? + detailsGroup.setText("Details"); + detailsGroup.setLayout(new FillLayout()); + GridData detailsGridData = new GridData(GridData.FILL_BOTH); + detailsGridData.widthHint = 200; + detailsGroup.setLayoutData(detailsGridData); + + detailPane = initDetailPane(detailsGroup); + + persisterList.setSelection(0); + updateDetailPane(persisterArray[0]); + + return content; + } + + private void initPersisterList(){ + for (int i = 0; i < persisterArray.length; ++i) { + + String name = (String)persisterArray[i].getProperty("converter_name"); + + // if someone was sloppy enough to not provide a name, then use the + // name of the class instead. + if (name == null || name.length() == 0) + name = persisterArray[i].getClass().getName(); + persisterList.add(name); + } + } + + + 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(""); + System.out.println("length="+details_prop_names.length); + for (int i=0; i<details_prop_names.length; i++){ + String val = (String) persister.getProperty(details_prop_names[i]); + + StyleRange styleRange = new StyleRange(); + styleRange.start = detailPane.getText().length(); + detailPane.append(details_prop_name_descriptions[i] + ":\n"); + styleRange.length = details_prop_names[i].length() + 1; + styleRange.fontStyle = SWT.BOLD; + detailPane.setStyleRange(styleRange); + + detailPane.append(val + "\n"); + + } + + } + + private void selectionMade(int selectedIndex) { + + logger.log(LogService.LOG_INFO, "Loaded: "+theFile.getPath()); + AlgorithmFactory persister =(AlgorithmFactory) bContext.getService(persisterArray[selectedIndex]); + Data[] dm = new Data[]{new BasicData(theFile.getPath(),String.class.getName())}; + dm = persister.createAlgorithm(dm, null, ciContext).execute(); + for(int i = 0; i<dm.length; i++){ + returnList.add(dm[i]); + } + close(true); + } + + public void createDialogButtons(Composite parent) { + Button select = new Button(parent, SWT.PUSH); + select.setText("Select"); + select.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + int index = persisterList.getSelectionIndex(); + if(index != -1){ + selectionMade(index); + } + } + }); + + Button cancel = new Button(parent, SWT.NONE); + cancel.setText("Cancel"); + cancel.addSelectionListener(new SelectionAdapter(){ + public void widgetSelected(SelectionEvent e) { + close(false); + } + }); + } + + public Composite createContent(Composite parent) { + return initGUI(parent); + } +} Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,130 @@ +/* + * Created on Aug 19, 2004 + */ +package org.cishell.reference.gui.persistence.save; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmProperty; +import org.cishell.framework.data.Data; +import org.cishell.service.conversion.Converter; +import org.eclipse.swt.SWT; +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 + */ +public class FileSaver { + private static File currentDir; + + private Shell parent; + private LogService logService; + private CIShellContext ciContext; + + public FileSaver(Shell parent, CIShellContext context){ + this.parent = parent; + this.ciContext = context; + this.logService = (LogService) ciContext.getService(LogService.class.getName()); + } + + private boolean confirmFileOverwrite(File file) { + String message = "The file:\n" + file.getPath() + + "\nalready exists. Are you sure you want to overwrite it?"; + logService.log(LogService.LOG_INFO, "Confirm File Overwrite: " + message); + return true; + } + + private boolean isSaveFileValid(File file) { + boolean valid = false; + if (file.isDirectory()) { + String message = "Destination cannot be a directory. Please choose a file"; + logService.log(LogService.LOG_ERROR, "Invalid Destination: " + message); + valid = false; + } else if (file.exists()) { + valid = confirmFileOverwrite(file); + } + else + valid = true ; + return valid; + } + + public boolean save(Converter converter, Data data) { + ServiceReference[] serviceReferenceArray = converter.getConverterChain(); + String outDataStr = (String)serviceReferenceArray[serviceReferenceArray.length-1] + .getProperty(AlgorithmProperty.OUT_DATA); + + String ext = outDataStr.substring(outDataStr.indexOf(':')+1); + + FileDialog dialog = new FileDialog(parent, SWT.SAVE); + + if (currentDir == null) { + currentDir = new File(System.getProperty("user.home")); + } + dialog.setFilterPath(currentDir.getPath()); + + dialog.setFilterExtensions(new String[]{"*" + ext}); + dialog.setText("Choose File"); + dialog.setFileName((String)data.getMetaData().get(AlgorithmProperty.LABEL)); + + boolean done = false; + + while (!done) { + String fileName = dialog.open(); + if (fileName != null) { + File selectedFile = new File(fileName); + if (!isSaveFileValid(selectedFile)) + continue; + if (ext != null && ext.length() != 0) + if (!selectedFile.getPath().endsWith(ext)) + selectedFile = new File(selectedFile.getPath() + ext) ; + + Data newData = converter.convert(data); + + copy((File)newData.getData(), selectedFile); + + if (selectedFile.isDirectory()) { + currentDir = selectedFile; + } else { + currentDir = new File(selectedFile.getParent()); + } + + done = true ; + + logService.log(LogService.LOG_INFO, "File saved: " + selectedFile.getPath() + "\n"); + //DataManagerService dms = (DataManagerService)context.getService(DataManagerService.class.getName()); + //dms.addData(data); + } else { + logService.log(LogService.LOG_INFO, "File save cancelled.\n"); + done = true; + return false; + } + } + return true; + } + + private boolean copy(File in, File out) { + try { + FileInputStream fis = new FileInputStream(in); + FileOutputStream fos = new FileOutputStream(out); + + FileChannel readableChannel = fis.getChannel(); + FileChannel writableChannel = fos.getChannel(); + + writableChannel.truncate(0); + writableChannel.transferFrom(readableChannel, 0, readableChannel.size()); + return true; + } + catch (IOException ioe) { + logService.log(LogService.LOG_ERROR, ioe.getMessage()); + return false; + } + } +} \ No newline at end of file Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,67 @@ +package org.cishell.reference.gui.persistence.save; + +import java.util.Dictionary; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.data.Data; +import org.cishell.service.conversion.Converter; +import org.cishell.service.conversion.DataConversionService; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; +import org.osgi.service.log.LogService; + +public class Save implements Algorithm { + Data[] data; + Dictionary parameters; + CIShellContext context; + + final Shell parentShell; + + DataConversionService conversionManager; + LogService logService; + + public Save(Data[] data, Dictionary parameters, CIShellContext context) { + this.data = data; + this.parameters = parameters; + this.context = context; + + parentShell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); + + conversionManager = (DataConversionService) context.getService( + DataConversionService.class.getName()); + + logService = (LogService)context.getService(LogService.class.getName()); + } + + public Data[] execute() { + //This only checks the first Data in the array + final Converter[] converters = conversionManager.findConverters(data[0], "file-ext:*"); + /* + for (int i = 0; i < converters.length; ++i) { + Dictionary dict = converters[i].getProperties(); + Object inDataObj = dict.get(AlgorithmProperty.IN_DATA); + Object outDataObj = dict.get(AlgorithmProperty.OUT_DATA); + } + */ + if (converters.length < 1) { + logService.log(LogService.LOG_ERROR, "No valid converters found!"); + } + else { + 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", + Save.class.getName(), + context); + sdc.createContent(parentShell); + sdc.open(); + }}); + } + } + return null; + } +} \ No newline at end of file Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,220 @@ +/* + * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research + * and Education in Information Visualization (http://iv.slis.indiana.edu/). + * + * Created on Jan 28, 2005 at Indiana University. + */ +package org.cishell.reference.gui.persistence.save; + +import java.util.Dictionary; +import java.util.Enumeration; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmProperty; +import org.cishell.framework.data.Data; +import org.cishell.service.conversion.Converter; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyleRange; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; + +import org.cishell.reference.gui.common.AbstractDialog; + +/** + * SavePersisterChooser 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; + private List converterList; + private StyledText detailPane; + //private Shell parent; + CIShellContext context; + //private LogService logService; + public static final Image QUESTION = Display.getCurrent().getSystemImage(SWT.ICON_QUESTION); + + /** + * Creates a new SavePersisterChooser 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 + */ + //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; + //this.logService = (LogService) context.getService(LogService.class.getName()); + } + + /* + * Initialize the GUI for this SavePersisterChooser + */ + private Composite initGUI(Composite parent) { + Composite content = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 2; + content.setLayout(layout); + //parent.setLayout(layout); + + Group converterGroup = new Group(content, SWT.NONE); + converterGroup.setText("Pick the Output Data Type"); + converterGroup.setLayout(new FillLayout()); + GridData persisterData = new GridData(GridData.FILL_BOTH); + persisterData.widthHint = 200; + converterGroup.setLayoutData(persisterData); + + converterList = new List(converterGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE); + initConverterList(); + converterList.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + List list = (List) e.getSource(); + int selection = list.getSelectionIndex(); + + if (selection != -1) { + updateDetailPane(converterArray[selection]); + } + } + }); + + 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); + detailsData.widthHint = 200; + detailsGroup.setLayoutData(detailsData); + + detailPane = initDetailPane(detailsGroup); + + //select the first item by default + converterList.setSelection(0); + updateDetailPane(converterArray[0]); + + return content; + } + + /* + * Initialize the Listbox of Persisters using the stored Persister array + */ + private void initConverterList() { + for (int i = 0; i < converterArray.length; ++i) { + Dictionary dict = converterArray[i].getProperties(); + + // get the name of the persister from the property map + String outData = (String) dict.get(AlgorithmProperty.LABEL); + + // if someone was sloppy enough to not provide a name, then use the + // name of the class instead. + if ((outData == null) || (outData.length() == 0)) { + outData = converterArray[i].getClass().getName(); + } + + converterList.add(outData); + } + } + + /* + * Sets up the DetailPane where the details from the Persister PropertyMaps are displayed. + */ + 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; + } + + /* + * Changes the information displayed in the DetailsPane whenever a new Persister + * is selected. + */ + private void updateDetailPane(Converter converter) { + Dictionary dict = converter.getProperties(); + Enumeration keysEnum = dict.keys(); + + detailPane.setText(""); + + 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(); + detailPane.append(key + ":\n"); + styleRange.length = key.toString().length() + 1; + styleRange.fontStyle = SWT.BOLD; + 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. + */ + protected void selectionMade(int selectedIndex) { + getShell().setVisible(false); + final Converter converter = converterArray[selectedIndex]; + final FileSaver saver = new FileSaver(getShell(), context); + close(saver.save(converter, data)); + } + + public void createDialogButtons(Composite parent) { + Button select = new Button(parent, SWT.PUSH); + select.setText("Select"); + select.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + int index = converterList.getSelectionIndex(); + + if (index != -1) { + selectionMade(index); + } + } + }); + + Button cancel = new Button(parent, SWT.NONE); + cancel.setText("Cancel"); + cancel.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + close(false); + } + }); + } + + public Composite createContent(Composite parent) { + if (converterArray.length == 1) { + final FileSaver saver = new FileSaver((Shell)parent, context); + close(saver.save(converterArray[0], data)); + return parent; + } + else { + return initGUI(parent); + } + } +} Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2006-09-28 19:11:20 UTC (rev 215) @@ -0,0 +1,24 @@ +package org.cishell.reference.gui.persistence.save; + +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.data.Data; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.metatype.MetaTypeProvider; + + +public class SaveFactory implements AlgorithmFactory { + + protected void activate(ComponentContext ctxt) {} + protected void deactivate(ComponentContext ctxt) {} + + public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { + return new Save(data, parameters, context); + } + public MetaTypeProvider createParameters(Data[] data) { + return null; + } +} \ 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: <bea...@us...> - 2006-10-02 15:06:11
|
Revision: 235 http://svn.sourceforge.net/cishell/?rev=235&view=rev Author: bearsfan Date: 2006-10-02 08:06:00 -0700 (Mon, 02 Oct 2006) Log Message: ----------- Using guiBuilder instead of logServices to display messages. Changed save.xml and SaveFactory to implement DataValidator (this not unit tested). Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 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/SaveFactory.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/l10n/ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/metatype/ Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2006-10-02 14:10:08 UTC (rev 234) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2006-10-02 15:06:00 UTC (rev 235) @@ -2,6 +2,6 @@ label=Save... description=Saves data to disk in_data=java.lang.Object -out_data=file:* +out_data=null service.pid=org.cishell.reference.gui.persistence.save.Save remoteable=false Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 2006-10-02 14:10:08 UTC (rev 234) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 2006-10-02 15:06:00 UTC (rev 235) @@ -8,5 +8,7 @@ <service> <provide interface= "org.cishell.framework.algorithm.AlgorithmFactory"/> + <provide interface= + "org.cishell.framework.algorithm.DataValidator"/> </service> </component> \ No newline at end of file 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 14:10:08 UTC (rev 234) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2006-10-02 15:06:00 UTC (rev 235) @@ -44,16 +44,15 @@ private boolean confirmFileOverwrite(File file) { String message = "The file:\n" + file.getPath() + "\nalready exists. Are you sure you want to overwrite it?"; - logService.log(LogService.LOG_INFO, "Confirm File Overwrite: " + message); - return true; - //return guiBuilder.showConfirm("File Overwrite", message, message); + return guiBuilder.showConfirm("File Overwrite", message, message); } private boolean isSaveFileValid(File file) { boolean valid = false; if (file.isDirectory()) { String message = "Destination cannot be a directory. Please choose a file"; - logService.log(LogService.LOG_ERROR, "Invalid Destination: " + message); + guiBuilder.showError("Invalid Destination", message, message); + //logService.log(LogService.LOG_ERROR, "Invalid Destination: " + message); valid = false; } else if (file.exists()) { valid = confirmFileOverwrite(file); @@ -112,17 +111,17 @@ done = true ; - //guiBuilder.showInformation("File Saved", - // "File successfully Saved", - // "File saved: " + selectedFile.getPath()); - logService.log(LogService.LOG_INFO, "File saved: " + selectedFile.getPath() + "\n"); + guiBuilder.showInformation("File Saved", + "File successfully Saved", + "File saved: " + selectedFile.getPath()); + //logService.log(LogService.LOG_INFO, "File saved: " + selectedFile.getPath() + "\n"); //DataManagerService dms = (DataManagerService)context.getService(DataManagerService.class.getName()); //dms.addData(data); } else { - //guiBuilder.showInformation("File Save Cancel", - // "File save has been cancelled", - // "File save has been cancelled"); - logService.log(LogService.LOG_INFO, "File save cancelled.\n"); + guiBuilder.showInformation("File Save Cancel", + "File save has been cancelled", + "File save has been cancelled"); + //logService.log(LogService.LOG_INFO, "File save cancelled.\n"); done = true; return false; } @@ -145,6 +144,7 @@ return true; } catch (IOException ioe) { + guiBuilder.showError("Copy Error", "IOException during copy", ioe.getMessage()); logService.log(LogService.LOG_ERROR, ioe.getMessage()); return false; } 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 14:10:08 UTC (rev 234) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2006-10-02 15:06:00 UTC (rev 235) @@ -4,7 +4,6 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.algorithm.DataValidator; import org.cishell.framework.data.Data; import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; @@ -13,7 +12,7 @@ import org.eclipse.ui.PlatformUI; import org.osgi.service.log.LogService; -public class Save implements Algorithm, DataValidator { +public class Save implements Algorithm { Data[] data; Dictionary parameters; CIShellContext context; @@ -43,11 +42,11 @@ 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(), - // "Please install a plugin that will save the data type to a file"); + //logService.log(LogService.LOG_ERROR, "No valid converters found!"); + guiBuilder.showError("No Converters", + "No valid converters for data type: " + + data[0].getData().getClass().getName(), + "Please install a plugin that will save the data type to a file"); } else { if (!parentShell.isDisposed()) { @@ -66,15 +65,4 @@ } return null; } - - public String validate(Data[] data) { - Converter[] converters = conversionManager.findConverters(data[0], "file-ext:*"); - if (converters.length == 0) { - return "No valid converters from " + - data[0].getData().getClass().getName() + " to any file extension"; - } - else { - return ""; - } - } } \ No newline at end of file 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 14:10:08 UTC (rev 234) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2006-10-02 15:06:00 UTC (rev 235) @@ -5,20 +5,40 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; +import org.cishell.framework.algorithm.DataValidator; import org.cishell.framework.data.Data; +import org.cishell.service.conversion.Converter; +import org.cishell.service.conversion.DataConversionService; import org.osgi.service.component.ComponentContext; import org.osgi.service.metatype.MetaTypeProvider; -public class SaveFactory implements AlgorithmFactory { +public class SaveFactory implements AlgorithmFactory, DataValidator { + private CIShellContext context; protected void activate(ComponentContext ctxt) {} protected void deactivate(ComponentContext ctxt) {} public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { + this.context = context; return new Save(data, parameters, context); } public MetaTypeProvider createParameters(Data[] data) { return null; } + + public String validate(Data[] data) { + DataConversionService conversionManager = (DataConversionService) context.getService( + DataConversionService.class.getName()); + + Converter[] converters = conversionManager.findConverters(data[0], "file-ext:*"); + if (converters.length == 0) { + return "No valid converters from " + + data[0].getData().getClass().getName() + " to any file extension"; + } + else { + return ""; + } + } + } \ 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: <bh...@us...> - 2006-10-04 01:43:35
|
Revision: 237 http://svn.sourceforge.net/cishell/?rev=237&view=rev Author: bh2 Date: 2006-10-02 09:14:28 -0700 (Mon, 02 Oct 2006) Log Message: ----------- Cleaned up File/Save stuff Modified Paths: -------------- 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/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/SaveFactory.java 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 2006-10-02 15:53:38 UTC (rev 236) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2006-10-02 16:14:28 UTC (rev 237) @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: Persistence Plug-in -Bundle-SymbolicName: org.cishell.reference.gui.persistence +Bundle-SymbolicName: org.cishell.reference.gui.persistence;singleton:=true Bundle-Version: 0.1.0.qualifier Bundle-ClassPath: . Bundle-Localization: plugin 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 15:53:38 UTC (rev 236) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2006-10-02 16:14:28 UTC (rev 237) @@ -52,7 +52,6 @@ if (file.isDirectory()) { String message = "Destination cannot be a directory. Please choose a file"; guiBuilder.showError("Invalid Destination", message, message); - //logService.log(LogService.LOG_ERROR, "Invalid Destination: " + message); valid = false; } else if (file.exists()) { valid = confirmFileOverwrite(file); @@ -111,17 +110,8 @@ done = true ; - guiBuilder.showInformation("File Saved", - "File successfully Saved", - "File saved: " + selectedFile.getPath()); - //logService.log(LogService.LOG_INFO, "File saved: " + selectedFile.getPath() + "\n"); - //DataManagerService dms = (DataManagerService)context.getService(DataManagerService.class.getName()); - //dms.addData(data); + logService.log(LogService.LOG_INFO, "Saved: " + selectedFile.getPath() + "\n"); } else { - guiBuilder.showInformation("File Save Cancel", - "File save has been cancelled", - "File save has been cancelled"); - //logService.log(LogService.LOG_INFO, "File save cancelled.\n"); done = true; return false; } @@ -145,7 +135,6 @@ } catch (IOException ioe) { guiBuilder.showError("Copy Error", "IOException during copy", ioe.getMessage()); - logService.log(LogService.LOG_ERROR, ioe.getMessage()); return false; } } 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 15:53:38 UTC (rev 236) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2006-10-02 16:14:28 UTC (rev 237) @@ -10,7 +10,6 @@ import org.cishell.service.guibuilder.GUIBuilderService; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import org.osgi.service.log.LogService; public class Save implements Algorithm { Data[] data; @@ -21,7 +20,7 @@ private GUIBuilderService guiBuilder; private DataConversionService conversionManager; - private LogService logService; + //private LogService logService; public Save(Data[] data, Dictionary parameters, CIShellContext context) { this.data = data; @@ -33,7 +32,7 @@ this.conversionManager = (DataConversionService) context.getService( DataConversionService.class.getName()); - this.logService = (LogService)context.getService(LogService.class.getName()); + //this.logService = (LogService)context.getService(LogService.class.getName()); this.guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); } 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 15:53:38 UTC (rev 236) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2006-10-02 16:14:28 UTC (rev 237) @@ -3,6 +3,7 @@ import java.util.Dictionary; import org.cishell.framework.CIShellContext; +import org.cishell.framework.LocalCIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.DataValidator; @@ -16,7 +17,9 @@ public class SaveFactory implements AlgorithmFactory, DataValidator { private CIShellContext context; - protected void activate(ComponentContext ctxt) {} + protected void activate(ComponentContext ctxt) { + context = new LocalCIShellContext(ctxt.getBundleContext()); + } protected void deactivate(ComponentContext ctxt) {} public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2006-10-04 01:44:16
|
Revision: 221 http://svn.sourceforge.net/cishell/?rev=221&view=rev Author: bh2 Date: 2006-09-28 15:52:25 -0700 (Thu, 28 Sep 2006) Log Message: ----------- added osgi-inf to build.properties and moved load and save to the start group of the File menu Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties trunk/clients/gui/org.cishell.reference.gui.persistence/build.properties 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 2006-09-28 22:17:19 UTC (rev 220) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2006-09-28 22:52:25 UTC (rev 221) @@ -1,4 +1,4 @@ -menu_path=file/additions/ +menu_path=File/start label=Load... description=This converter allows users to select file from the file system and load it to Data Model window in_data=null Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2006-09-28 22:17:19 UTC (rev 220) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2006-09-28 22:52:25 UTC (rev 221) @@ -1,4 +1,4 @@ -menu_path=File/Save +menu_path=File/start label=Save... description=Saves data to disk in_data=java.lang.Object Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/build.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/build.properties 2006-09-28 22:17:19 UTC (rev 220) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/build.properties 2006-09-28 22:52:25 UTC (rev 221) @@ -1,4 +1,5 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ - . + .,\ + OSGI-INF/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bh...@us...> - 2006-10-23 21:50:06
|
Revision: 309 http://svn.sourceforge.net/cishell/?rev=309&view=rev Author: bh2 Date: 2006-10-23 14:49:51 -0700 (Mon, 23 Oct 2006) Log Message: ----------- finally finished feature to allow files to be saved w/o a converter. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 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/SaveFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2006-10-23 21:19:35 UTC (rev 308) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2006-10-23 21:49:51 UTC (rev 309) @@ -1,7 +1,7 @@ menu_path=File/start label=Save... description=Saves data to disk -in_data=file:* +in_data=java.lang.Object out_data=null service.pid=org.cishell.reference.gui.persistence.save.Save remoteable=false 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-23 21:19:35 UTC (rev 308) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2006-10-23 21:49:51 UTC (rev 309) @@ -26,9 +26,8 @@ Data[] data; Dictionary parameters; CIShellContext context; + Shell parentShell; - final Shell parentShell; - private GUIBuilderService guiBuilder; private DataConversionService conversionManager; @@ -44,8 +43,6 @@ this.parameters = parameters; this.context = context; - this.parentShell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); - this.conversionManager = (DataConversionService) context.getService( DataConversionService.class.getName()); @@ -64,9 +61,11 @@ if (converters.length < 1 && !(data[0].getData() instanceof File)) { guiBuilder.showError("No Converters", "No valid converters for data type: " + - data[0].getData().getClass().getName(), + data[0].getFormat(), "Please install a plugin that will save the data type to a file"); } else { + parentShell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); + if (!parentShell.isDisposed()) { guiRun(new Runnable() { public void run() { 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-23 21:19:35 UTC (rev 308) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2006-10-23 21:49:51 UTC (rev 309) @@ -16,6 +16,10 @@ /** * Create a Save object + * + * TODO: Should also support if we can convert to file, but have + * no final file:X->file-ext:* converter. + * * @author bmarkine * */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ter...@us...> - 2007-05-14 18:58:04
|
Revision: 399 http://svn.sourceforge.net/cishell/?rev=399&view=rev Author: terkhorn Date: 2007-05-14 11:57:45 -0700 (Mon, 14 May 2007) Log Message: ----------- Added VERY BASIC support for "View as..." option for files seen in the data manager window. Currently you can only use this option by selecting it from the "File" menu. You cannot right-click the file and select view as yet, but I will add that ASAP. Most changes are seen in org.cishell.reference.gui.persistence. Modified Paths: -------------- 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/view/FileView.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.xml trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 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/ViewWithDataChooser.java 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 2007-05-14 18:55:13 UTC (rev 398) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2007-05-14 18:57:45 UTC (rev 399) @@ -10,6 +10,7 @@ org.cishell.framework.algorithm, org.cishell.framework.data, org.cishell.reference.gui.common, + org.cishell.reference.service.metatype, org.cishell.service.conversion, org.cishell.service.guibuilder, org.osgi.framework;version="1.3.0", @@ -18,6 +19,6 @@ 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 +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 Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.properties (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.properties 2007-05-14 18:57:45 UTC (rev 399) @@ -0,0 +1,7 @@ +menu_path=File/additions +label=View with... +description=This algorithm does this and this... +in_data=java.lang.Object +out_data=null +service.pid=org.cishell.reference.gui.persistence.viewwith.FileViewWith +remoteable=true Added: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.xml (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.xml 2007-05-14 18:57:45 UTC (rev 399) @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<component name="org.cishell.reference.gui.persistence.viewwith.FileViewWith.component" immediate="false"> + <implementation class="org.cishell.reference.gui.persistence.viewwith.FileViewWithFactory"/> + <properties entry="OSGI-INF/viewwith.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/view/FileView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2007-05-14 18:55:13 UTC (rev 398) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2007-05-14 18:57:45 UTC (rev 399) @@ -31,6 +31,7 @@ static GUIBuilderService guiBuilder; LogService logger; Program program; + // Program programTwo; File tempFile; public FileView(Data[] data, Dictionary parameters, CIShellContext context) { @@ -118,7 +119,19 @@ public void run() { program = Program.findProgram("txt"); }}); + /* + Display.getDefault().syncExec(new Runnable() { + public void run() { + programTwo = Program.findProgram("doc"); + }}); + if (programTwo == null) { + System.out.println("***\nYO!\nNo doc viewer\n"); + } else { + System.out.println("!!!\nHEY!\nDoc viewer found\n"); + + } + */ if (program == null) { guiBuilder.showError("No Text Viewer", "No valid text viewer for the .txt file. " + Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2007-05-14 18:57:45 UTC (rev 399) @@ -0,0 +1,222 @@ +package org.cishell.reference.gui.persistence.viewwith; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.util.Dictionary; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.data.Data; +import org.cishell.service.conversion.Converter; +import org.cishell.service.conversion.DataConversionService; +import org.cishell.service.guibuilder.GUIBuilderService; +import org.eclipse.swt.program.Program; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.osgi.service.log.LogService; + +/* + * @author Felix Terkhorn (ter...@gm...), Weixia Huang (hu...@in...) + */ +public class FileViewWith implements Algorithm { + Data[] data; + Dictionary parameters; + CIShellContext context; + DataConversionService conversionManager; + static GUIBuilderService guiBuilder; + LogService logger; + Program program; + Program programTwo; + Program programThree; + File tempFile; + + public FileViewWith(Data[] data, Dictionary parameters, CIShellContext context) { + this.data = data; + this.parameters = parameters; + this.context = context; + + conversionManager = (DataConversionService) context.getService( + DataConversionService.class.getName()); + + logger = (LogService)context.getService(LogService.class.getName()); + guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); + + } + public File getTempFile(){ + File tempFile; + + String tempPath = System.getProperty("java.io.tmpdir"); + File tempDir = new File(tempPath+File.separator+"temp"); + if(!tempDir.exists()) + tempDir.mkdir(); + try{ + tempFile = File.createTempFile("xxx-Session-", ".txt", tempDir); + + }catch (IOException e){ + logger.log(LogService.LOG_ERROR, e.toString()); + tempFile = new File (tempPath+File.separator+"temp"+File.separator+"temp.txt"); + + } + return tempFile; + } + + public Data[] execute() { + boolean lastSaveSuccessful = false; + String format; + + String viewWith = (String) parameters.get("viewWith"); + + Display display; + IWorkbenchWindow[] windows; + final Shell parentShell; + + windows = PlatformUI.getWorkbench().getWorkbenchWindows(); + if (windows.length == 0){ + return null; + } + parentShell = windows[0].getShell(); + display = PlatformUI.getWorkbench().getDisplay(); + tempFile = getTempFile(); + + for (int i = 0; i < data.length; i++){ + Object theData = data[i].getData(); + format = data[i].getFormat(); + if (theData instanceof File || + format.startsWith("file:text/") || + format.startsWith("file-ext:")){ + copy((File)data[i].getData(), tempFile); + lastSaveSuccessful = true; + }else{ + final Converter[] converters = conversionManager.findConverters(data[i], "file-ext:*"); + + if (converters.length < 1) { + guiBuilder.showError("No Converters", + "No valid converters for data type: " + + data[i].getData().getClass().getName(), + "Please install a plugin that will save the data type to a file"); + } + else if (converters.length == 1){ + //If length=1, use the unique path to save it directly + //and bring the text editor. + Data newData = converters[0].convert(data[i]); + copy((File)newData.getData(), tempFile); + lastSaveSuccessful = true; + } + else { + if (!parentShell.isDisposed()) { + DataViewer dataViewer = new DataViewer(parentShell, data[i], converters); + display.syncExec(dataViewer); + lastSaveSuccessful = dataViewer.isSaved; + tempFile = dataViewer.theFile; + } + } + } + + + Display.getDefault().syncExec(new Runnable() { + public void run() { + program = Program.findProgram("txt"); + }}); + + Display.getDefault().syncExec(new Runnable() { + public void run() { + programTwo = Program.findProgram("doc"); + }}); + + Display.getDefault().syncExec(new Runnable() { + public void run() { + programThree = Program.findProgram("htm"); + }}); + + + if (program == null && programTwo == null && programThree == null) { + guiBuilder.showError("No Viewers for TXT, DOC, or HTM", + "No valid viewers for .txt, .doc, or .htm files. " + + "The file is located at: "+tempFile.getAbsolutePath(), + "Unable to open default text viewer. File is located at: "+ + tempFile.getAbsolutePath()); + } + else { + if (lastSaveSuccessful == true) { + if (viewWith.equals("txt")) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + program.execute(tempFile.getAbsolutePath()); + }}); + } else if (viewWith.equals("doc")) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + programTwo.execute(tempFile.getAbsolutePath()); + }}); + } else if (viewWith.equals("html")) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + programThree.execute(tempFile.getAbsolutePath()); + }}); + } else { + // Try to run it with txt viewer... + Display.getDefault().syncExec(new Runnable() { + public void run() { + program.execute(tempFile.getAbsolutePath()); + }}); + } + } + } + + + + } + return null; + } + + public static boolean copy(File in, File out) { + try { + FileInputStream fis = new FileInputStream(in); + FileOutputStream fos = new FileOutputStream(out); + + FileChannel readableChannel = fis.getChannel(); + FileChannel writableChannel = fos.getChannel(); + + writableChannel.truncate(0); + writableChannel.transferFrom(readableChannel, 0, readableChannel.size()); + fis.close(); + fos.close(); + return true; + } + catch (IOException ioe) { + guiBuilder.showError("Copy Error", "IOException during copy", ioe.getMessage()); + return false; + } + } + + final class DataViewer implements Runnable { + Shell shell; + boolean isSaved; + Data theData; + File theFile = getTempFile(); + Converter[] theConverters; + + DataViewer (Shell parentShell, Data data, Converter[] converters){ + this.shell = parentShell; + this.theData = data; + this.theConverters = converters; + } + + public void run() { + // lots of persisters found, return the chooser + ViewWithDataChooser vdc = new ViewWithDataChooser("View as...", theFile, shell, + theData, theConverters, context); + vdc.open(); + isSaved = vdc.isSaved(); + } + } + + + + +} \ No newline at end of file Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java 2007-05-14 18:57:45 UTC (rev 399) @@ -0,0 +1,127 @@ +package org.cishell.reference.gui.persistence.viewwith; + +import java.io.IOException; +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.data.Data; +import org.cishell.reference.service.metatype.BasicAttributeDefinition; +import org.cishell.reference.service.metatype.BasicMetaTypeProvider; +import org.cishell.reference.service.metatype.BasicObjectClassDefinition; +import org.eclipse.swt.program.Program; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.PlatformUI; +import org.osgi.service.component.ComponentContext; +import org.osgi.service.metatype.AttributeDefinition; +import org.osgi.service.metatype.MetaTypeInformation; +import org.osgi.service.metatype.MetaTypeProvider; +import org.osgi.service.metatype.MetaTypeService; +import org.osgi.service.metatype.ObjectClassDefinition; + + +// Felix: +// See edu.iu.nwb.visualization.prefuse.beta.common +// It implements AlgorithmFactory and adds dropbox boxes... +// You will need to do something similar, but much less complicated, here, I believe. + +public class FileViewWithFactory implements AlgorithmFactory { + Program programTxt; + Program programDoc; + Program programHtml; + private MetaTypeProvider provider; +// private MetaTypeInformation originalProvider; // taken from PrefuseBetaAlgorithmFactory +// private String pid; // taken from PrefuseBetaAlgFactory + + protected void activate(ComponentContext ctxt) { + //You may delete all references to metatype service if + //your algorithm does not require parameters and return + //null in the createParameters() method + //MetaTypeService mts = (MetaTypeService)ctxt.locateService("MTS"); + //provider = mts.getMetaTypeInformation(ctxt.getBundleContext().getBundle()); + // bruce says these should be commented out... + } + protected void deactivate(ComponentContext ctxt) { + provider = null; + } + + public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { + return new FileViewWith(data, parameters, context); + } + + + private String[] createKeyArray() { + String[] keys = new String[1]; + keys[0] = "Viewer"; + /* + for(int ii = 1; ii <= schema.getColumnCount(); ii++) { + keys[ii] = schema.getColumnName(ii - 1); + System.out.println("keys["+ii+"] = " + schema.getColumnName(ii - 1) + "; "); + } + */ + + return keys; + } + + public MetaTypeProvider createParameters(Data[] data) { + //ObjectClassDefinition oldDefinition = provider.getObjectClassDefinition(this.pid, null); + // read the API for creating on ObjectClassDefinition + // and create a basic one ... + // BasicObjectClassDefinition oldDefinition = new ObjectClassDefinition(); + + BasicObjectClassDefinition definition; + //try { + definition = new BasicObjectClassDefinition("fileViewWithDefinition", "Application viewer type", "Please choose an application viewer to read this file.\nThe application associated with the chosen extension will be called.", null); + //} catch (IOException e) { + //definition = new BasicObjectClassDefinition("fileViewWithDef", "fileViewWithName", "This is an OCD for fileViewWith", null); + //} + +// String[] dialogAttributesArray = createKeyArray(); + + + Display display; + + + display = PlatformUI.getWorkbench().getDisplay(); + + Display.getDefault().syncExec(new Runnable() { + public void run() { + programTxt = Program.findProgram("txt"); + }}); + + Display.getDefault().syncExec(new Runnable() { + public void run() { + programDoc = Program.findProgram("doc"); + }}); + + Display.getDefault().syncExec(new Runnable() { + public void run() { + programHtml = Program.findProgram("htm"); + }}); + + System.err.println(definition.getID()); + + String[] defValStringArray = null; //doesn't actually work yet... + String[] myOptionLabels = new String[] {"TXT","DOC","HTML"}; + String[] myOptionValues = new String[] {"txt","doc","html"}; + + if (programTxt == null) { + myOptionLabels[0] = ""; + } + if (programDoc == null) { + myOptionLabels[1] = ""; + } + if (programHtml == null) { + myOptionLabels[2] = ""; + } + AttributeDefinition ad = new BasicAttributeDefinition("viewWith", "View file as", "Type of viewer", AttributeDefinition.STRING /*string*/, 0, defValStringArray/*String[] defaultValue*/, null /*validator*/, myOptionLabels, myOptionValues); + definition.addAttributeDefinition(ObjectClassDefinition.REQUIRED, ad); + + AttributeDefinition[] definitions = definition.getAttributeDefinitions(ObjectClassDefinition.ALL); + + + MetaTypeProvider provider = new BasicMetaTypeProvider(definition); + return provider; + } +} \ No newline at end of file Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java 2007-05-14 18:57:45 UTC (rev 399) @@ -0,0 +1,44 @@ +package org.cishell.reference.gui.persistence.viewwith; + +import java.io.File; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.data.Data; +import org.cishell.reference.gui.persistence.save.SaveDataChooser; +import org.cishell.service.conversion.Converter; + +import org.eclipse.swt.widgets.Shell; + +/* + * @author Felix Terkhorn (ter...@gm...) + * + */ +public class ViewWithDataChooser extends SaveDataChooser { + private File tempFile; + boolean isSaved = false; + Converter[] converters; + Data theData; + + public ViewWithDataChooser(String title, File tempFile, Shell parent, + Data data, Converter[] converters, CIShellContext context){ + super (data, parent, converters, title, context); + + this.tempFile = tempFile; + this.converters = converters; + this.theData = data; + } + + protected void selectionMade(int selectedIndex) { + getShell().setVisible(false); + final Converter converter = converterArray[selectedIndex]; + Data newData = converter.convert(theData); + isSaved = FileViewWith.copy((File)newData.getData(), tempFile); + close(true); + } + + public boolean isSaved(){ + return isSaved; + } + + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2008-03-25 19:21:25
|
Revision: 707 http://cishell.svn.sourceforge.net/cishell/?rev=707&view=rev Author: mwlinnem Date: 2008-03-25 12:18:32 -0700 (Tue, 25 Mar 2008) Log Message: ----------- Made CIShell 1.0 compatible. Modified Paths: -------------- 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/FileLoad.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/save/FileSaver.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 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/ViewWithDataChooser.java 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 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2008-03-25 19:18:32 UTC (rev 707) @@ -2,17 +2,17 @@ Bundle-ManifestVersion: 2 Bundle-Name: Persistence Plug-in Bundle-SymbolicName: org.cishell.reference.gui.persistence;singleton:=true -Bundle-Version: 0.7.0 +Bundle-Version: 1.0.0 Bundle-ClassPath: . Bundle-Localization: plugin Import-Package: org.cishell.app.service.datamanager, - org.cishell.framework, - org.cishell.framework.algorithm, - org.cishell.framework.data, + 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.common, org.cishell.reference.service.metatype, - org.cishell.service.conversion, - org.cishell.service.guibuilder, + org.cishell.service.conversion;version="1.0.0", + org.cishell.service.guibuilder;version="1.0.0", org.osgi.framework;version="1.3.0", org.osgi.service.component;version="1.0.0", org.osgi.service.log;version="1.3.0", Modified: 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 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2008-03-25 19:18:32 UTC (rev 707) @@ -3,26 +3,24 @@ import java.io.File; import java.util.ArrayList; +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.service.guibuilder.GUIBuilderService; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +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.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; - - import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; import org.osgi.service.log.LogService; -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.algorithm.Algorithm; -import org.cishell.framework.data.Data; -import org.cishell.framework.data.BasicData; -import org.cishell.service.guibuilder.GUIBuilderService; - /* * @author Weixia(Bonnie) Huang (hu...@in...) */ @@ -48,7 +46,8 @@ } - public Data[] execute() { + public Data[] execute() throws AlgorithmExecutionException { + try { // int counter = PlatformUI.getWorkbench().getWorkbenchWindowCount(); // System.out.println("counter is "+counter); // ?? why getActiveWorkbenchWindow() didn't work?? @@ -56,7 +55,7 @@ final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); if (windows.length ==0){ - return null; + throw new AlgorithmExecutionException("Cannot obtain workbench window needed to open dialog."); } Display display = PlatformUI.getWorkbench().getDisplay(); @@ -76,10 +75,14 @@ } return returnDM; } - else { - return null; + else { + throw new AlgorithmExecutionException("No data could be loaded."); } - + } catch (AlgorithmExecutionException e1) { + throw e1; + } catch (Throwable e2) { + throw new AlgorithmExecutionException(e2); + } } public static String getFileExtension(File theFile) { @@ -209,7 +212,7 @@ }catch (Exception e){ - e.printStackTrace(); + throw new RuntimeException(e); } }//end run() 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 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2008-03-25 19:18:32 UTC (rev 707) @@ -23,13 +23,8 @@ protected void activate(ComponentContext ctxt) { bcontext = ctxt.getBundleContext(); } - protected void deactivate(ComponentContext ctxt) {} - + public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { return new FileLoad(context, bcontext); } - public MetaTypeProvider createParameters(Data[] data) { - return null; - } - } \ No newline at end of file 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 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2008-03-25 19:18:32 UTC (rev 707) @@ -13,6 +13,7 @@ import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.data.Data; import org.cishell.framework.data.DataProperty; +import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.cishell.service.guibuilder.GUIBuilderService; import org.eclipse.swt.SWT; @@ -107,7 +108,7 @@ dialog.setText("Choose File"); - String fileLabel = (String)data.getMetaData().get(DataProperty.LABEL); + String fileLabel = (String)data.getMetadata().get(DataProperty.LABEL); String suggestedFileName = getFileName(fileLabel); dialog.setFileName(suggestedFileName + "." + ext); @@ -128,9 +129,10 @@ if (ext != null && ext.length() != 0) if (!selectedFile.getPath().endsWith(ext) && !ext.equals("*")) selectedFile = new File(selectedFile.getPath()+'.'+ ext); - + try { Data newData = converter.convert(data); - + + copy((File)newData.getData(), selectedFile); if (selectedFile.isDirectory()) { @@ -140,7 +142,10 @@ } done = true; - + } catch (ConversionException e1) { + this.log.log(LogService.LOG_ERROR, "Error occurred while converting data to saved format.", e1); + return false; + } log.log(LogService.LOG_INFO, "Saved: " + selectedFile.getPath()); } else { done = true; 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 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2008-03-25 19:18:32 UTC (rev 707) @@ -6,6 +6,7 @@ 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.AlgorithmProperty; import org.cishell.framework.data.Data; @@ -54,7 +55,8 @@ * * @return Null for this algorithm */ - public Data[] execute() { + public Data[] execute() throws AlgorithmExecutionException { + try { //This only checks the first Data in the array final Converter[] converters = conversionManager.findConverters(data[0], "file-ext:*"); @@ -105,7 +107,10 @@ } } return null; + } catch (Throwable e) { + throw new AlgorithmExecutionException(e); } + } private void guiRun(Runnable run) { if (Thread.currentThread() == Display.getDefault().getThread()) { 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 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2008-03-25 19:18:32 UTC (rev 707) @@ -17,6 +17,7 @@ import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.data.Data; import org.cishell.reference.gui.common.AbstractDialog; +import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.StyleRange; @@ -308,11 +309,15 @@ * of opening the FileSaver and saving the model. * @param selectedIndex The chosen converter */ - protected void selectionMade(int selectedIndex) { + protected void selectionMade(int selectedIndex){ + try { getShell().setVisible(false); final Converter converter = converterArray[selectedIndex]; final FileSaver saver = new FileSaver(getShell(), context); close(saver.save(converter, data)); + } catch (Exception e) { + throw new RuntimeException(e); + } } /** @@ -327,7 +332,7 @@ select.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { int index = converterList.getSelectionIndex(); - + if (index != -1) { selectionMade(index); } 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 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2008-03-25 19:18:32 UTC (rev 707) @@ -33,12 +33,6 @@ 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 @@ -53,15 +47,6 @@ } /** - * 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 Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2008-03-25 19:18:32 UTC (rev 707) @@ -9,7 +9,9 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.data.Data; +import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; import org.cishell.service.guibuilder.GUIBuilderService; @@ -28,7 +30,6 @@ Dictionary parameters; CIShellContext context; DataConversionService conversionManager; - static GUIBuilderService guiBuilder; LogService logger; Program program; // Program programTwo; @@ -43,9 +44,8 @@ DataConversionService.class.getName()); logger = (LogService)context.getService(LogService.class.getName()); - guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); - - } + } + public File getTempFile(){ File tempFile; @@ -82,7 +82,8 @@ return tempFile; } - public Data[] execute() { + public Data[] execute() throws AlgorithmExecutionException { + try { boolean lastSaveSuccessful = false; boolean isCSVFile = false;//TC181 String format; @@ -93,7 +94,7 @@ windows = PlatformUI.getWorkbench().getWorkbenchWindows(); if (windows.length == 0){ - return null; + throw new AlgorithmExecutionException("Cannot get workbench window."); } parentShell = windows[0].getShell(); display = PlatformUI.getWorkbench().getDisplay(); @@ -150,10 +151,9 @@ final Converter[] converters = conversionManager.findConverters(data[i], "file-ext:*"); if (converters.length < 1) { - guiBuilder.showError("No Converters", - "No valid converters for data type: " + - data[i].getData().getClass().getName(), - "Please install a plugin that will save the data type to a file"); + throw new AlgorithmExecutionException("No valid converters for data type: " + + data[i].getData().getClass().getName() + + ". Please install a plugin that will save the data type to a file"); } else if (converters.length == 1){ //If length=1, use the unique path to save it directly @@ -202,10 +202,10 @@ } */ if (program == null) { - guiBuilder.showError("No Text Viewer", + throw new AlgorithmExecutionException( "No valid text viewer for the .txt file. " + - "The file is located at: "+tempFile.getAbsolutePath(), - "Unable to open default text viewer. File is located at: "+ + "The file is located at: "+tempFile.getAbsolutePath() + + ". Unable to open default text viewer. File is located at: "+ tempFile.getAbsolutePath()); } else { @@ -220,10 +220,15 @@ } - return null; + return null; + } catch (ConversionException e1) { + throw new AlgorithmExecutionException("Error converting data to target view format.", e1); + } catch (Throwable e2){ + throw new AlgorithmExecutionException(e2); + } } - public static boolean copy(File in, File out) { + public static boolean copy(File in, File out) throws AlgorithmExecutionException{ try { FileInputStream fis = new FileInputStream(in); FileOutputStream fos = new FileOutputStream(out); @@ -238,9 +243,8 @@ return true; } catch (IOException ioe) { - guiBuilder.showError("Copy Error", "IOException during copy", ioe.getMessage()); - return false; - } + throw new AlgorithmExecutionException("IOException during copy", ioe); + } } final class DataViewer implements Runnable { Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileViewFactory.java 2008-03-25 19:18:32 UTC (rev 707) @@ -12,24 +12,8 @@ public class FileViewFactory implements AlgorithmFactory { -// private MetaTypeProvider provider; - protected void activate(ComponentContext ctxt) { - //You may delete all references to metatype service if - //your algorithm does not require parameters and return - //null in the createParameters() method -// MetaTypeService mts = (MetaTypeService)ctxt.locateService("MTS"); -// provider = mts.getMetaTypeInformation(ctxt.getBundleContext().getBundle()); - } - protected void deactivate(ComponentContext ctxt) { -// provider = null; - } - - public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { + public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { return new FileView(data, parameters, context); } - public MetaTypeProvider createParameters(Data[] data) { -// return provider; - return null; - } } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/ViewDataChooser.java 2008-03-25 19:18:32 UTC (rev 707) @@ -6,7 +6,6 @@ import org.cishell.framework.data.Data; import org.cishell.reference.gui.persistence.save.SaveDataChooser; import org.cishell.service.conversion.Converter; - import org.eclipse.swt.widgets.Shell; /* @@ -26,12 +25,16 @@ this.theData = data; } - protected void selectionMade(int selectedIndex) { + protected void selectionMade(int selectedIndex){ + try { getShell().setVisible(false); final Converter converter = converterArray[selectedIndex]; Data newData = converter.convert(theData); isSaved = FileView.copy((File)newData.getData(), tempFile); close(true); + } catch (Exception e) { + throw new RuntimeException(e); + } } public boolean isSaved(){ Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2008-03-25 19:18:32 UTC (rev 707) @@ -9,7 +9,9 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; +import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.data.Data; +import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; import org.cishell.service.guibuilder.GUIBuilderService; @@ -66,7 +68,7 @@ return tempFile; } - public Data[] execute() { + public Data[] execute() throws AlgorithmExecutionException { boolean lastSaveSuccessful = false; String format; @@ -104,16 +106,25 @@ else if (converters.length == 1){ //If length=1, use the unique path to save it directly //and bring the text editor. - Data newData = converters[0].convert(data[i]); + try { + Data newData = converters[0].convert(data[i]); copy((File)newData.getData(), tempFile); lastSaveSuccessful = true; + } catch (ConversionException e) { + this.logger.log(LogService.LOG_WARNING, "Error while converting to target save format. Will attempt to use other available converters."); + } } else { if (!parentShell.isDisposed()) { + try { DataViewer dataViewer = new DataViewer(parentShell, data[i], converters); display.syncExec(dataViewer); + lastSaveSuccessful = dataViewer.isSaved; tempFile = dataViewer.theFile; + } catch (Throwable e1) { + throw new AlgorithmExecutionException(e1); + } } } } 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 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java 2008-03-25 19:18:32 UTC (rev 707) @@ -1,23 +1,20 @@ package org.cishell.reference.gui.persistence.viewwith; -import java.io.IOException; 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.ParameterMutator; import org.cishell.framework.data.Data; import org.cishell.reference.service.metatype.BasicAttributeDefinition; import org.cishell.reference.service.metatype.BasicMetaTypeProvider; import org.cishell.reference.service.metatype.BasicObjectClassDefinition; import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; import org.osgi.service.component.ComponentContext; import org.osgi.service.metatype.AttributeDefinition; -import org.osgi.service.metatype.MetaTypeInformation; import org.osgi.service.metatype.MetaTypeProvider; -import org.osgi.service.metatype.MetaTypeService; import org.osgi.service.metatype.ObjectClassDefinition; @@ -26,7 +23,7 @@ // It implements AlgorithmFactory and adds dropbox boxes... // You will need to do something similar, but much less complicated, here, I believe. -public class FileViewWithFactory implements AlgorithmFactory { +public class FileViewWithFactory implements AlgorithmFactory, ParameterMutator { Program programTxt; Program programDoc; Program programHtml; @@ -46,8 +43,9 @@ return new FileViewWith(data, parameters, context); } - public MetaTypeProvider createParameters(Data[] data) { - + public ObjectClassDefinition mutateParameters(Data[] data, + ObjectClassDefinition parameters) { + BasicObjectClassDefinition definition; definition = new BasicObjectClassDefinition("fileViewWithDefinition", "Application Viewer Type", "Please choose an application viewer to read this file.", null); @@ -118,7 +116,6 @@ AttributeDefinition ad = new BasicAttributeDefinition("viewWith", "View file as", "Type of viewer", AttributeDefinition.STRING /*string*/, 0, defValStringArray/*String[] defaultValue*/, null /*validator*/, myOptionLabels, myOptionValues); definition.addAttributeDefinition(ObjectClassDefinition.REQUIRED, ad); - MetaTypeProvider provider = new BasicMetaTypeProvider(definition); - return provider; - } + return definition; + } } \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java 2008-03-25 18:05:28 UTC (rev 706) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/ViewWithDataChooser.java 2008-03-25 19:18:32 UTC (rev 707) @@ -5,8 +5,8 @@ import org.cishell.framework.CIShellContext; import org.cishell.framework.data.Data; import org.cishell.reference.gui.persistence.save.SaveDataChooser; +import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; - import org.eclipse.swt.widgets.Shell; /* @@ -26,12 +26,16 @@ this.theData = data; } - protected void selectionMade(int selectedIndex) { - getShell().setVisible(false); + protected void selectionMade(int selectedIndex){ + try { + getShell().setVisible(false); final Converter converter = converterArray[selectedIndex]; Data newData = converter.convert(theData); isSaved = FileViewWith.copy((File)newData.getData(), tempFile); close(true); + } catch (Exception e) { + throw new RuntimeException(e); + } } public boolean isSaved(){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2008-03-27 17:47:22
|
Revision: 728 http://cishell.svn.sourceforge.net/cishell/?rev=728&view=rev Author: mwlinnem Date: 2008-03-27 10:46:12 -0700 (Thu, 27 Mar 2008) Log Message: ----------- Refactored disgusting inline anonymous class. Modified Paths: -------------- 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/Save.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java Removed Paths: ------------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 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 2008-03-27 15:38:15 UTC (rev 727) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2008-03-27 17:46:12 UTC (rev 728) @@ -4,7 +4,6 @@ Bundle-SymbolicName: org.cishell.reference.gui.persistence;singleton:=true Bundle-Version: 1.0.0 Bundle-ClassPath: . -Bundle-Localization: plugin Import-Package: org.cishell.app.service.datamanager, org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", Deleted: 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 2008-03-27 15:38:15 UTC (rev 727) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2008-03-27 17:46:12 UTC (rev 728) @@ -1,217 +0,0 @@ -/* - * Created on Aug 19, 2004 - */ -package org.cishell.reference.gui.persistence.save; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.channels.FileChannel; - -import org.cishell.framework.CIShellContext; -import org.cishell.framework.algorithm.AlgorithmProperty; -import org.cishell.framework.data.Data; -import org.cishell.framework.data.DataProperty; -import org.cishell.service.conversion.ConversionException; -import org.cishell.service.conversion.Converter; -import org.cishell.service.guibuilder.GUIBuilderService; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; -import org.osgi.service.log.LogService; - -/** - * Persist the file to disk for the user - * - * @author Team - */ -public class FileSaver { - private static File currentDir; - - private Shell parent; - - private GUIBuilderService guiBuilder; - private LogService log; - - - /** - * Initializes services to output messages - * - * @param parent - * @param context - */ - public FileSaver(Shell parent, CIShellContext context){ - this.parent = parent; - this.guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); - this.log = (LogService) context.getService(LogService.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()) { - String message = "Destination cannot be a directory. Please choose a file"; - guiBuilder.showError("Invalid Destination", message, ""); - valid = false; - } else if (file.exists()) { - valid = confirmFileOverwrite(file); - } - else - valid = true ; - 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) { - String outDataStr = (String)converter.getProperties().get(AlgorithmProperty.OUT_DATA); - - String ext = outDataStr.substring(outDataStr.indexOf(':')+1); - - if ((""+ext).startsWith(".")) { - ext = ext.substring(1); - } - - FileDialog dialog = new FileDialog(parent, SWT.SAVE); - - if (currentDir == null) { - currentDir = new File(System.getProperty("user.home") + File.separator + "anything"); - } - dialog.setFilterPath(currentDir.getPath()); - - - if (ext != null && !ext.equals("*")) { - dialog.setFilterExtensions(new String[]{"*." + ext}); - } - - dialog.setText("Choose File"); - - String fileLabel = (String)data.getMetadata().get(DataProperty.LABEL); - String suggestedFileName = getFileName(fileLabel); - dialog.setFileName(suggestedFileName + "." + ext); - -// if (fileLabel == null) { -// dialog.setFileName("*." + ext); -// } else { -// dialog.setFileName(fileLabel + '.' + ext); -// } - - boolean done = false; - - while (!done) { - String fileName = dialog.open(); - if (fileName != null) { - File selectedFile = new File(fileName); - if (!isSaveFileValid(selectedFile)) - continue; - if (ext != null && ext.length() != 0) - if (!selectedFile.getPath().endsWith(ext) && !ext.equals("*")) - selectedFile = new File(selectedFile.getPath()+'.'+ ext); - try { - Data newData = converter.convert(data); - - - copy((File)newData.getData(), selectedFile); - - if (selectedFile.isDirectory()) { - currentDir = new File(selectedFile + File.separator + "anything"); - } else { - currentDir = new File(selectedFile.getParent() + File.separator + "anything"); - } - - done = true; - } catch (ConversionException e1) { - this.log.log(LogService.LOG_ERROR, "Error occurred while converting data to saved format.", e1); - return false; - } - log.log(LogService.LOG_INFO, "Saved: " + selectedFile.getPath()); - } else { - done = true; - return false; - } - } - 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); - FileOutputStream fos = new FileOutputStream(out); - - FileChannel readableChannel = fis.getChannel(); - FileChannel writableChannel = fos.getChannel(); - - writableChannel.truncate(0); - writableChannel.transferFrom(readableChannel, 0, readableChannel.size()); - fis.close(); - fos.close(); - return true; - } - catch (IOException ioe) { - guiBuilder.showError("Copy Error", "IOException during copy", ioe.getMessage()); - return false; - } - } - - private String getFileName(String fileLabel) { - - //index variables will be -1 if index is not found. - int descriptionEndIndex = fileLabel.lastIndexOf(":"); - int filePathEndIndex = fileLabel.lastIndexOf(File.separator); - - //doesn't matter if either variable is -1, since startIndex will be - //zero and none of the string will be cut off the front. - int startIndex = Math.max(descriptionEndIndex, filePathEndIndex) + 1; - - String fileNameWithExtension = fileLabel.substring(startIndex); - - - //find the first character of the file name extension. - int extensionBeginIndex = fileNameWithExtension.lastIndexOf("."); - - int endIndex; - - if (extensionBeginIndex != -1) { - //we found a period in the file name. - endIndex = extensionBeginIndex; //cut off everything after - //first period. - } else { - //we didn't find an extension on the file name. - endIndex = fileNameWithExtension.length(); // don't cut any off the end. - } - - String fileNameWithoutExtension = fileNameWithExtension.substring(0, endIndex); - - String fileName = fileNameWithoutExtension; - return fileName; - } -} \ No newline at end of file Added: 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 (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2008-03-27 17:46:12 UTC (rev 728) @@ -0,0 +1,217 @@ +/* + * Created on Aug 19, 2004 + */ +package org.cishell.reference.gui.persistence.save; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; + +import org.cishell.framework.CIShellContext; +import org.cishell.framework.algorithm.AlgorithmProperty; +import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; +import org.cishell.service.conversion.ConversionException; +import org.cishell.service.conversion.Converter; +import org.cishell.service.guibuilder.GUIBuilderService; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.osgi.service.log.LogService; + +/** + * Persist the file to disk for the user + * + * @author Team + */ +public class FileSaver { + private static File currentDir; + + private Shell parent; + + private GUIBuilderService guiBuilder; + private LogService log; + + + /** + * Initializes services to output messages + * + * @param parent + * @param context + */ + public FileSaver(Shell parent, CIShellContext context){ + this.parent = parent; + this.guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); + this.log = (LogService) context.getService(LogService.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()) { + String message = "Destination cannot be a directory. Please choose a file"; + guiBuilder.showError("Invalid Destination", message, ""); + valid = false; + } else if (file.exists()) { + valid = confirmFileOverwrite(file); + } + else + valid = true ; + 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) { + String outDataStr = (String)converter.getProperties().get(AlgorithmProperty.OUT_DATA); + + String ext = outDataStr.substring(outDataStr.indexOf(':')+1); + + if ((""+ext).startsWith(".")) { + ext = ext.substring(1); + } + + FileDialog dialog = new FileDialog(parent, SWT.SAVE); + + if (currentDir == null) { + currentDir = new File(System.getProperty("user.home") + File.separator + "anything"); + } + dialog.setFilterPath(currentDir.getPath()); + + + if (ext != null && !ext.equals("*")) { + dialog.setFilterExtensions(new String[]{"*." + ext}); + } + + dialog.setText("Choose File"); + + String fileLabel = (String)data.getMetadata().get(DataProperty.LABEL); + String suggestedFileName = getFileName(fileLabel); + dialog.setFileName(suggestedFileName + "." + ext); + +// if (fileLabel == null) { +// dialog.setFileName("*." + ext); +// } else { +// dialog.setFileName(fileLabel + '.' + ext); +// } + + boolean done = false; + + while (!done) { + String fileName = dialog.open(); + if (fileName != null) { + File selectedFile = new File(fileName); + if (!isSaveFileValid(selectedFile)) + continue; + if (ext != null && ext.length() != 0) + if (!selectedFile.getPath().endsWith(ext) && !ext.equals("*")) + selectedFile = new File(selectedFile.getPath()+'.'+ ext); + try { + Data newData = converter.convert(data); + + + copy((File)newData.getData(), selectedFile); + + if (selectedFile.isDirectory()) { + currentDir = new File(selectedFile + File.separator + "anything"); + } else { + currentDir = new File(selectedFile.getParent() + File.separator + "anything"); + } + + done = true; + } catch (ConversionException e1) { + this.log.log(LogService.LOG_ERROR, "Error occurred while converting data to saved format.", e1); + return false; + } + log.log(LogService.LOG_INFO, "Saved: " + selectedFile.getPath()); + } else { + done = true; + return false; + } + } + 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); + FileOutputStream fos = new FileOutputStream(out); + + FileChannel readableChannel = fis.getChannel(); + FileChannel writableChannel = fos.getChannel(); + + writableChannel.truncate(0); + writableChannel.transferFrom(readableChannel, 0, readableChannel.size()); + fis.close(); + fos.close(); + return true; + } + catch (IOException ioe) { + guiBuilder.showError("Copy Error", "IOException during copy", ioe.getMessage()); + return false; + } + } + + private String getFileName(String fileLabel) { + + //index variables will be -1 if index is not found. + int descriptionEndIndex = fileLabel.lastIndexOf(":"); + int filePathEndIndex = fileLabel.lastIndexOf(File.separator); + + //doesn't matter if either variable is -1, since startIndex will be + //zero and none of the string will be cut off the front. + int startIndex = Math.max(descriptionEndIndex, filePathEndIndex) + 1; + + String fileNameWithExtension = fileLabel.substring(startIndex); + + + //find the first character of the file name extension. + int extensionBeginIndex = fileNameWithExtension.lastIndexOf("."); + + int endIndex; + + if (extensionBeginIndex != -1) { + //we found a period in the file name. + endIndex = extensionBeginIndex; //cut off everything after + //first period. + } else { + //we didn't find an extension on the file name. + endIndex = fileNameWithExtension.length(); // don't cut any off the end. + } + + String fileNameWithoutExtension = fileNameWithExtension.substring(0, endIndex); + + String fileName = fileNameWithoutExtension; + return fileName; + } +} \ No newline at end of file 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 2008-03-27 15:38:15 UTC (rev 727) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2008-03-27 17:46:12 UTC (rev 728) @@ -17,7 +17,6 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.osgi.framework.ServiceReference; - /** * Save algorithm for persisting a data object * @@ -72,26 +71,8 @@ guiRun(new Runnable() { public void run() { if (converters.length == 0) { - final FileSaver saver = new FileSaver(parentShell, context); - saver.save(new Converter(){ - Dictionary props = new Hashtable(); - - public Data convert(Data data) { - return data; - } - - public AlgorithmFactory getAlgorithmFactory() { - return null; - } - - public ServiceReference[] getConverterChain() { - return null; - } - - public Dictionary getProperties() { - props.put(AlgorithmProperty.OUT_DATA, "file:*"); - return props; - }}, data[0]); + FileSaver saver = new FileSaver(parentShell, context); + saver.save(new NoConversionConverter(), data[0]); } else if (converters.length == 1) { final FileSaver saver = new FileSaver(parentShell, context); saver.save(converters[0], data[0]); @@ -119,4 +100,25 @@ parentShell.getDisplay().syncExec(run); } } + + private class NoConversionConverter implements Converter { + Dictionary props = new Hashtable(); + + public Data convert(Data data) { + return data; + } + + public AlgorithmFactory getAlgorithmFactory() { + return null; + } + + public ServiceReference[] getConverterChain() { + return null; + } + + public Dictionary getProperties() { + props.put(AlgorithmProperty.OUT_DATA, "file:*"); + return props; + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2008-03-27 21:25:40
|
Revision: 735 http://cishell.svn.sourceforge.net/cishell/?rev=735&view=rev Author: mwlinnem Date: 2008-03-27 14:25:36 -0700 (Thu, 27 Mar 2008) Log Message: ----------- If there is no way to save something such that it goes through a validator as it is saved, we now try to save it anyway. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 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/OSGI-INF/save.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 2008-03-27 21:06:14 UTC (rev 734) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 2008-03-27 21:25:36 UTC (rev 735) @@ -8,7 +8,5 @@ <service> <provide interface= "org.cishell.framework.algorithm.AlgorithmFactory"/> - <provide interface= - "org.cishell.framework.algorithm.DataValidator"/> </service> </component> \ No newline at end of file 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 2008-03-27 21:06:14 UTC (rev 734) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/FileSaver.java 2008-03-27 21:25:36 UTC (rev 735) @@ -88,8 +88,11 @@ public boolean save(Converter converter, Data data) { String outDataStr = (String)converter.getProperties().get(AlgorithmProperty.OUT_DATA); - String ext = outDataStr.substring(outDataStr.indexOf(':')+1); - + String ext = ""; + if (outDataStr.startsWith("file-ext:")) { + ext = outDataStr.substring(outDataStr.indexOf(':')+1); + } + if ((""+ext).startsWith(".")) { ext = ext.substring(1); } 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 2008-03-27 21:06:14 UTC (rev 734) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2008-03-27 21:25:36 UTC (rev 735) @@ -1,6 +1,5 @@ package org.cishell.reference.gui.persistence.save; -import java.io.File; import java.util.Dictionary; import java.util.Hashtable; @@ -9,6 +8,7 @@ import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.algorithm.AlgorithmProperty; +import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; @@ -17,6 +17,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; import org.osgi.framework.ServiceReference; +import org.osgi.service.log.LogService; /** * Save algorithm for persisting a data object * @@ -30,6 +31,7 @@ private GUIBuilderService guiBuilder; private DataConversionService conversionManager; + private LogService log; /** * Sets up default services for the algorithm @@ -46,6 +48,7 @@ this.conversionManager = (DataConversionService) context.getService( DataConversionService.class.getName()); + this.log = (LogService) context.getService(LogService.class.getName()); this.guiBuilder = (GUIBuilderService)context.getService(GUIBuilderService.class.getName()); } @@ -55,45 +58,87 @@ * @return Null for this algorithm */ public Data[] execute() throws AlgorithmExecutionException { - try { - //This only checks the first Data in the array - final Converter[] converters = conversionManager.findConverters(data[0], "file-ext:*"); + //NOTE: A "converter" here is actually a converter path + //starting with the format for the data we want to save + //and ending in a output format + Data dataToSave = data[0]; - if (converters.length < 1 && !(data[0].getData() instanceof File)) { - guiBuilder.showError("No Converters", - "No valid converters for data type: " + - data[0].getFormat(), - "Please install a plugin that will save the data type to a file"); - } else { - parentShell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); - - if (!parentShell.isDisposed()) { - guiRun(new Runnable() { - public void run() { - if (converters.length == 0) { - FileSaver saver = new FileSaver(parentShell, context); - saver.save(new NoConversionConverter(), data[0]); - } else if (converters.length == 1) { - final FileSaver saver = new FileSaver(parentShell, context); - saver.save(converters[0], data[0]); - } else { - SaveDataChooser sdc = new SaveDataChooser(data[0], - parentShell, converters, - "Save", - context); - sdc.createContent(new Shell(parentShell)); - sdc.open(); - } - }}); + //first, try to save the normal way, which is using validators to validate the output. + String saveThroughValidators = "file-ext:*"; + Object firstAttemptResult = tryToSave(dataToSave, saveThroughValidators); + if (firstAttemptResult instanceof Boolean) { + boolean succeeded = ((Boolean) firstAttemptResult).booleanValue(); + if (succeeded) { + System.out.println("Success"); + return null; //FILE SAVED SUCCESSFULLY. DONE. + } else { + System.out.println("No converter"); + this.log.log(LogService.LOG_WARNING, "No converters found that can save file through a validator." + + " Attempting to save without validating."); } + } else { //result instanceof Exception + Exception reasonForFailure = (Exception) firstAttemptResult; + this.log.log(LogService.LOG_WARNING, "Exception occurred while attempting to save" + + " file using a validator. Attempting to save without validating."); + System.out.println("Exception"); } - return null; - } catch (Throwable e) { - throw new AlgorithmExecutionException(e); + + System.out.println("Trying without validators"); + + //if saving with validators didn't work, try to save it without using validators + String saveWithoutValidators = "file:*"; + Object secondAttemptResult = tryToSave(dataToSave, saveWithoutValidators); + if (secondAttemptResult instanceof Boolean) { + boolean succeeded = ((Boolean) secondAttemptResult).booleanValue(); + if (succeeded) { + return null; //FILE SAVED SUCCESSFULLY. DONE. + } else { + throw new AlgorithmExecutionException("No converters found that could save file. Save failed"); + } + } else { //result instanceof Exception + Exception reasonForFailure2 = (Exception) secondAttemptResult; + throw new AlgorithmExecutionException("Exception occurred while attempting to save", reasonForFailure2); + } + } + + //returns True if save was successful + //return False if there are no converter chains available to save to the given format + //return an Exception if an exception occurred while attempting to save + private Object tryToSave(final Data dataToSave, String formatToSaveTo) { + final Converter[] converters = conversionManager.findConverters(dataToSave, formatToSaveTo); + if (converters.length == 0) {return new Boolean(false);}; + + parentShell = PlatformUI.getWorkbench().getWorkbenchWindows()[0].getShell(); + if (parentShell.isDisposed()) {return makeParentShellDisposedException();}; + + try { + guiRun(new Runnable() { + public void run() { + if (converters.length == 1){ + //only one possible choice in how to save data. Just do it. + Converter onlyConverter = converters[0]; + final FileSaver saver = new FileSaver(parentShell, context); + saver.save(onlyConverter, dataToSave); + } else { //converters.length > 1 + //multiple ways to save the data. Let user choose. + SaveDataChooser saveChooser = new SaveDataChooser(dataToSave, + parentShell, converters, "Save", context); + saveChooser.createContent(new Shell(parentShell)); + saveChooser.open(); + } + }}); + } catch (Exception e) { + return e; + } + + return new Boolean(true); } - } - private void guiRun(Runnable run) { + private AlgorithmExecutionException makeParentShellDisposedException() { + return new AlgorithmExecutionException("Attempted to use disposed parent shell"); + } + + private void guiRun(Runnable run) { if (Thread.currentThread() == Display.getDefault().getThread()) { run.run(); } else { @@ -121,4 +166,8 @@ return props; } } + + private Data removeExtension(Data data) { + return new BasicData(data.getMetadata(), data, ""); + } } \ No newline at end of file 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 2008-03-27 21:06:14 UTC (rev 734) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveDataChooser.java 2008-03-27 21:25:36 UTC (rev 735) @@ -17,7 +17,6 @@ import org.cishell.framework.algorithm.AlgorithmProperty; import org.cishell.framework.data.Data; import org.cishell.reference.gui.common.AbstractDialog; -import org.cishell.service.conversion.ConversionException; 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.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 2008-03-27 21:06:14 UTC (rev 734) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2008-03-27 21:25:36 UTC (rev 735) @@ -23,7 +23,7 @@ * @author bmarkine * */ -public class SaveFactory implements AlgorithmFactory, DataValidator { +public class SaveFactory implements AlgorithmFactory { private CIShellContext context; /** @@ -45,26 +45,4 @@ this.context = context; return new Save(data, parameters, context); } - - /** - * 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()); - - //Fix me - //Bonnie:why only check data[0]? An user can select multiple objects from data manager. - Converter[] converters = conversionManager.findConverters(data[0], "file-ext:*"); - if (converters.length == 0 && !(data[0].getData() instanceof File)) { - return "No valid converters from " + - data[0].getData().getClass().getName() + " to any file extension"; - } - else { - return ""; - } - } - } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2008-03-31 19:43:10
|
Revision: 748 http://cishell.svn.sourceforge.net/cishell/?rev=748&view=rev Author: mwlinnem Date: 2008-03-31 12:42:39 -0700 (Mon, 31 Mar 2008) Log Message: ----------- Added preference service functionality and fixed default directory for file loading on linux. Will test to see if it works on Windows as well. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/load.properties trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/load.xml trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/ Copied: trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence (from rev 745, trunk/clients/gui/org.cishell.reference.gui.persistence) Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2008-03-28 20:59:27 UTC (rev 745) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2008-03-31 19:42:39 UTC (rev 748) @@ -13,6 +13,7 @@ org.cishell.service.conversion;version="1.0.0", org.cishell.service.guibuilder;version="1.0.0", org.osgi.framework;version="1.3.0", + org.osgi.service.cm;version="1.2.0", org.osgi.service.component;version="1.0.0", org.osgi.service.log;version="1.3.0", org.osgi.service.metatype;version="1.1.0", Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/load.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2008-03-28 20:59:27 UTC (rev 745) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2008-03-31 19:42:39 UTC (rev 748) @@ -5,3 +5,5 @@ out_data=java.lang.Object service.pid=org.cishell.reference.gui.persistence.load.FileLoad remoteable=true +prefs_published=local +receive_prefs=true Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/load.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.xml 2008-03-28 20:59:27 UTC (rev 745) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/load.xml 2008-03-31 19:42:39 UTC (rev 748) @@ -8,5 +8,7 @@ <service> <provide interface= "org.cishell.framework.algorithm.AlgorithmFactory"/> + <provide interface= + "org.osgi.service.cm.ManagedService"/> </service> </component> \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML 2008-03-28 20:59:27 UTC (rev 745) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/OSGI-INF/metatype/METADATA.XML 2008-03-31 19:42:39 UTC (rev 748) @@ -1,9 +1,10 @@ <?xml version="1.0" encoding="UTF-8"?> <metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"> - <OCD name="FileView" id="org.cishell.reference.gui.persistence.view.FileView.OCD" + <OCD name="File Load" id="org.cishell.reference.gui.persistence.load.FileLoad.prefs.local.OCD" description=""> + <AD name="Default load directory" id="loadDir" type="String" default="directory:sampledata/"/> </OCD> - <Designate pid="org.cishell.reference.gui.persistence.view.FileView"> - <Object ocdref="org.cishell.reference.gui.persistence.view.FileView.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> -</metatype:MetaData> +</metatype:MetaData> \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/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 2008-03-28 20:59:27 UTC (rev 745) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2008-03-31 19:42:39 UTC (rev 748) @@ -2,6 +2,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Dictionary; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; @@ -10,8 +11,6 @@ import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; import org.cishell.service.guibuilder.GUIBuilderService; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; @@ -24,113 +23,98 @@ /* * @author Weixia(Bonnie) Huang (hu...@in...) */ -public class FileLoad implements Algorithm{ - - private static File currentDir; - +public class FileLoad implements Algorithm { + private final LogService logger; private final GUIBuilderService guiBuilder; private BundleContext bContext; private CIShellContext ciContext; + private static String defaultLoadDirectory; - public FileLoad(CIShellContext ciContext, BundleContext bContext) { + public FileLoad(CIShellContext ciContext, BundleContext bContext, Dictionary prefProperties) { this.ciContext = ciContext; this.bContext = bContext; logger = (LogService) ciContext.getService(LogService.class.getName()); guiBuilder = (GUIBuilderService)ciContext.getService(GUIBuilderService.class.getName()); - + + //unpack preference properties + if (defaultLoadDirectory == null) { + defaultLoadDirectory = (String) prefProperties.get("loadDir"); + } } - - public void selectionChanged(IAction action, ISelection selection) { - } public Data[] execute() throws AlgorithmExecutionException { - try { -// int counter = PlatformUI.getWorkbench().getWorkbenchWindowCount(); -// System.out.println("counter is "+counter); -// ?? why getActiveWorkbenchWindow() didn't work?? - Data[] returnDM; + //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. - final IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - if (windows.length ==0){ - throw new AlgorithmExecutionException("Cannot obtain workbench window needed to open dialog."); - } - - Display display = PlatformUI.getWorkbench().getDisplay(); - DataUpdater dataUpdater = new DataUpdater (windows[0]); - if (Thread.currentThread() != display.getThread()) { - display.syncExec(dataUpdater); + display.syncExec(fileLoader); } else { - dataUpdater.run(); + fileLoader.run(); } - if (!dataUpdater.returnList.isEmpty()){ - int size = dataUpdater.returnList.size(); - returnDM = new Data[size]; - for(int index=0; index<size; index++){ - returnDM[index]=(Data)dataUpdater.returnList.get(index); - } - return returnDM; - } - else { - this.logger.log(LogService.LOG_WARNING, "File loading canceled"); - return new Data[0]; - } - } catch (AlgorithmExecutionException e1) { - throw e1; - } catch (Throwable e2) { - throw new AlgorithmExecutionException(e2); - } + //return loaded file data + + Data[] loadedFileData = extractLoadedFileData(fileLoader); + return loadedFileData; } - public static String getFileExtension(File theFile) { - String fileName = theFile.getName() ; - String extension ; - if (fileName.lastIndexOf(".") != -1) - extension = fileName.substring(fileName.lastIndexOf(".")+1) ; - else - extension = "" ; - return extension ; - } - - final class DataUpdater implements Runnable{ + final class FileLoadRunnable implements Runnable{ boolean loadFileSuccess = false; IWorkbenchWindow window; - ArrayList returnList = new ArrayList(); + //this is how we return values from the runnable + public ArrayList returnList = new ArrayList(); - DataUpdater (IWorkbenchWindow window){ + FileLoadRunnable (IWorkbenchWindow window){ this.window = window; - } + } public void run (){ - - FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN); - if (currentDir == null) { - currentDir = new File(System.getProperty("osgi.install.area").replace("file:","") - + "sampledata"); - - if (!currentDir.exists()) { - currentDir = new File(System.getProperty("osgi.install.area").replace("file:","") - + "sampledata" +File.separator + "anything"); - } - } - dialog.setFilterPath(currentDir.getPath()); + FileDialog dialog = new FileDialog(window.getShell(), SWT.OPEN); +// if (currentDir == null) { +// currentDir = new File(System.getProperty("osgi.install.area").replace("file:","") +// + "sampledata"); +// +// if (!currentDir.exists()) { +// currentDir = new File(System.getProperty("osgi.install.area").replace("file:","") +// + "sampledata" +File.separator + "anything"); +// } +// } + System.err.println("defaultLoadDirectory is " + defaultLoadDirectory); + File currentDir = new File(defaultLoadDirectory); //? good way to do this? + String absolutePath = currentDir.getAbsolutePath(); + System.err.println("absolutePath:" + absolutePath); + String name = currentDir.getName(); + System.err.println("name:" + name); + dialog.setFilterPath(absolutePath); + // dialog.setFilterPath(name); dialog.setText("Select a File"); String fileName = dialog.open(); + System.out.println("Resulting file name!:" + fileName); if (fileName == null) { return; } - File file = new File(fileName); - - if (file.isDirectory()) { - currentDir = new File(file + File.separator + "anything"); - } else { - currentDir = new File(file.getParent() + File.separator + "anything"); - } + + File file = new File(fileName); + if (file.isDirectory()) { + System.out.println("directory"); + defaultLoadDirectory = file.getAbsolutePath(); + } else { + + // File parentFile = file.getParentFile(); + // if (parentFile != null) { + System.out.println("file"); + defaultLoadDirectory = file.getParentFile().getAbsolutePath(); + // } + } String fileExtension = getFileExtension(file).toLowerCase(); String filter = "(&(type=validator)(in_data=file-ext:"+fileExtension+"))"; @@ -217,7 +201,44 @@ } }//end run() + + 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 ; + } } //end class - - + + 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.returnList.isEmpty()){ + int size = dataUpdater.returnList.size(); + loadedFileData = new Data[size]; + for(int index=0; index<size; index++){ + loadedFileData[index]=(Data)dataUpdater.returnList.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 Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/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 2008-03-28 20:59:27 UTC (rev 745) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2008-03-31 19:42:39 UTC (rev 748) @@ -2,29 +2,51 @@ //standard java import java.util.Dictionary; +import java.util.Enumeration; +import java.util.Hashtable; -//osgi -import org.osgi.framework.BundleContext; -import org.osgi.service.component.ComponentContext; -import org.osgi.service.metatype.MetaTypeProvider; - -//cishell import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.Data; +import org.osgi.framework.BundleContext; +import org.osgi.service.cm.ConfigurationException; +import org.osgi.service.cm.ManagedService; +import org.osgi.service.component.ComponentContext; /* * @author Weixia(Bonnie) Huang (hu...@in...) */ -public class FileLoadFactory implements AlgorithmFactory { +public class FileLoadFactory implements AlgorithmFactory, ManagedService { private BundleContext bcontext; + private Dictionary properties = new Hashtable(); protected void activate(ComponentContext ctxt) { bcontext = ctxt.getBundleContext(); } public Algorithm createAlgorithm(Data[] data, Dictionary parameters, CIShellContext context) { - return new FileLoad(context, bcontext); + return new FileLoad(context, bcontext, properties); } + + public void updated(Dictionary properties) throws ConfigurationException { + this.properties = properties; + printPreferences(properties); + } + + 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(); + + while (propertiesKeys.hasMoreElements()) { + String propertiesKey = (String) propertiesKeys.nextElement(); + + Object propertiesValue = properties.get(propertiesKey); + System.out.println(" " + propertiesKey + ":" + propertiesValue); + } + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |