|
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.
|