Hi Michael,

The problem with the previous open file plugin is that it only works
well for a single file in the case where you have an option that can
potentially be different for each file you select (e.g. the GML 2 plugin
requires a template file which is different for each schema). Also there
is that extra drop down to select the type which always confuses me as I
expect to just use the regular file type drop down.

With the new approach if you have files such as Shape files which have
no options then all you will see is one panel with the finish button.
This is what happens most of the time.

The only time you will see the middle panel is if All files is selected
and there are two loaders that can load the file (this only happens for
*.gml, *.xml where it could be a FME GML or GML 2 file).

The options panel will only appear if the loader has options, currently
this is only for GML 2, although we may want to add in SRSID options for
other file types at some point.

So for simple files most of the time there is just one panel, for some
cases there are a maximum of two extra clicks.

Paul


Michaël Michaud wrote:
> Hi Paul,
>
> Screenshots look nice.
> I'm not sure I understood every capability you propose to add.
> For me, an important thing is to keep simple things easy to do. I like 
> to be able to load simple files or files needing one or two options 
> (configuration file, checkbox option or combobox option) from a single 
> panel.
> For imports with multi options or for a per-file configuration, may be 
> it is necessary to have several panels.
>
> my 2 cts
>
> Michaël
>
> Paul Austin a écrit :
>
>   
>> All,
>>
>> I have now implemented what I think should be the 'Open File...' menu 
>> item in the File menu which will allow uses to open files and add them 
>> as layers to the current Project.
>>
>> This first screen shot shows the first page of the wizard where you 
>> can select the File type (or leave it as All Files) and then select 
>> one or more files to load.
>>
>>
>>
>> If All files was selected as the file filter and one or more of the 
>> file extensions could be loaded by more than one file loader (e.g. 
>> *.xml can be loaded by the GML Loader and FME GML Loader) then the 
>> following wziard panel will be displayed when you select the Next 
>> button on the previous page. This will allow you to select which 
>> loader to use for each extension.
>>
>>
>>
>> If you uncheck the Use the same Settings for say *.xml you can select 
>> the specific loader to use for each file as shown below.
>>
>>
>>
>> Some file loaders have options (e.g. GML loader requires a template 
>> file) if the loader has options these will be displayed on the next 
>> wizard page. If no loaders have options then this page will not be 
>> displayed. This is where we could add in options for the SRS ID to use 
>> for the loaded data set. Options that are required will not allow the 
>> finish button to be selected until a value is specified.
>>
>>
>>
>> Again if you uncheck the Use same setting for all XXX then you can 
>> define the options on a per file basis as shown below.
>>
>>
>>
>> This new infrastructure also handles ZIP, GZ, tar and tar.gz, files by 
>> looking at the contents of the zip file and finding the appropriate 
>> file loader for that type of file. You can mix and match different 
>> types of file in the zip file (e.g. TIF, SHP and GML) and each file 
>> will be loaded.
>>
>> The FileLoader interface (attached) is implemented by loaders that can 
>> load a file from a URI. There are implementations to wrap the file 
>> DataSource and file ReferencedImageFactory implementations so they can 
>> be loaded using the new framework.
>>
>> The following code fragments show how these existing classes are wrapped
>>
>>    DataSourceFileLoader gmlLoader = addStandardReaderWriterFileDataSource(
>>      "GML 2.0", StandardReaderWriterFileDataSource.GML.class);
>>
>>    gmlLoader.addOptionField(
>>      StandardReaderWriterFileDataSource.GML.INPUT_TEMPLATE_FILE_KEY,
>>      "FileString", true);
>>
>>    addFactory(new GraphicImageFactory(), new String[] {"wld", "bpw", "jpw", 
>> "gfw"});
>>  :
>>
>>  private DataSourceFileLoader addStandardReaderWriterFileDataSource(
>>    String description, Class readerClass) {
>>    List extensions = getExtensions(readerClass);
>>    if (extensions != null) {
>>      DataSourceFileLoader fileLoader = new DataSourceFileLoader(
>>        workbenchContext, readerClass, description, extensions);
>>      registry.createEntry(FileLoader.KEY, fileLoader);
>>      return fileLoader;
>>    }
>>    return null;
>>  }
>>
>>  private List getExtensions(Class readerClass) {
>>    try {
>>      String[] extensions = 
>> ((StandardReaderWriterFileDataSource)readerClass.newInstance()).getExtensions();
>>      return Arrays.asList(extensions);
>>    } catch (Exception e) {
>>      
>> workbenchContext.getWorkbench().getFrame().log(StringUtil.stackTrace(e));
>>      return null;
>>    }
>>  }
>>
>>  private void addFactory(ReferencedImageFactory factory, String[] 
>> supportFileExtensions) {
>>    if (factory.isAvailable()) {
>>      ReferencedImageFactoryFileLoader loader = new 
>> ReferencedImageFactoryFileLoader(
>>        workbenchContext, factory, supportFileExtensions);
>>      registry.createEntry(FileLoader.KEY, loader);
>>    }
>>  }
>>  
>>
>>
>> I'm going to bundle up a plugin so people can try this out and if they 
>> like it I'll start work on getting it ready to commit.
>>
>> Paul
>>
>> ------------------------------------------------------------------------
>>
>> package com.revolsys.jump.ui.file;
>>
>> import java.net.URI;
>> import java.util.Collection;
>> import java.util.List;
>> import java.util.Map;
>>
>> import com.vividsolutions.jump.task.TaskMonitor;
>>
>> public interface FileLoader {
>>  public String KEY = FileLoader.class.getName();
>>  
>>  public Collection<String> getFileExtensions();
>>
>>  public String getDescription();
>>  
>>  public boolean open(TaskMonitor monitor, URI uri, Map<String,Object> 
>> options);
>>  
>>  public List<Option> getOptionMetadata();
>> }
>>  
>>
>> ------------------------------------------------------------------------
>>
>> package com.revolsys.jump.ui.file;
>>
>> public class Option {
>>    private String name;
>>
>>    private String type;
>>
>>    private boolean required;
>>
>>    public Option(final String name, final String type, final boolean 
>> required) {
>>        super();
>>        this.name = name;
>>        this.type = type;
>>        this.required = required;
>>    }
>>
>>    public String getName() {
>>        return name;
>>    }
>>
>>    public String getType() {
>>        return type;
>>    }
>>
>>    public boolean isRequired() {
>>        return required;
>>    }
>> }
>>  
>>
>> ------------------------------------------------------------------------
>>
>> package com.revolsys.jump.ui.file;
>>
>> import java.io.File;
>> import java.net.URI;
>> import java.util.ArrayList;
>> import java.util.Arrays;
>> import java.util.Collection;
>> import java.util.HashMap;
>> import java.util.Iterator;
>> import java.util.List;
>> import java.util.Map;
>>
>> import com.vividsolutions.jump.I18N;
>> import com.vividsolutions.jump.coordsys.CoordinateSystemRegistry;
>> import com.vividsolutions.jump.feature.FeatureCollection;
>> import com.vividsolutions.jump.io.datasource.Connection;
>> import com.vividsolutions.jump.io.datasource.DataSource;
>> import com.vividsolutions.jump.io.datasource.DataSourceQuery;
>> import com.vividsolutions.jump.task.TaskMonitor;
>> import com.vividsolutions.jump.util.CollectionUtil;
>> import com.vividsolutions.jump.util.LangUtil;
>> import com.vividsolutions.jump.util.StringUtil;
>> import com.vividsolutions.jump.workbench.WorkbenchContext;
>> import com.vividsolutions.jump.workbench.model.LayerManager;
>> import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
>> import com.vividsolutions.jump.workbench.ui.GUIUtil;
>> import com.vividsolutions.jump.workbench.ui.HTMLFrame;
>> import com.vividsolutions.jump.workbench.ui.LayerNamePanel;
>> import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
>>
>> public class DataSourceFileLoader extends AbstractFileLoader {
>>    private Class dataSourceClass;
>>
>>    private WorkbenchContext workbenchContext;
>>
>>    public DataSourceFileLoader(WorkbenchContext workbenchContext,
>>        Class dataSourceClass, String description, List<String> extensions) {
>>        super(description, extensions);
>>        this.workbenchContext = workbenchContext;
>>        this.dataSourceClass = dataSourceClass;
>>    }
>>
>>    public boolean open(TaskMonitor monitor, URI uri,
>>        Map<String, Object> options) {
>>        DataSource dataSource = (DataSource)LangUtil
>>            .newInstance(dataSourceClass);
>>        Map<String, Object> properties = toProperties(uri, options);
>>        dataSource.setProperties(properties);
>>        String name = UriUtil.getFileNameWithoutExtension(uri);
>>        DataSourceQuery dataSourceQuery = new DataSourceQuery(dataSource, 
>> null,
>>            name);
>>        ArrayList exceptions = new ArrayList();
>>        monitor.report("Loading " + dataSourceQuery.toString() + "...");
>>
>>        Connection connection = 
>> dataSourceQuery.getDataSource().getConnection();
>>        try {
>>            FeatureCollection dataset = dataSourceQuery.getDataSource()
>>                .installCoordinateSystem(
>>                    connection.executeQuery(dataSourceQuery.getQuery(),
>>                        exceptions, monitor),
>>                    CoordinateSystemRegistry.instance(workbenchContext
>>                        .getBlackboard()));
>>            if (dataset != null) {
>>                LayerManager layerManager = 
>> workbenchContext.getLayerManager();
>>                layerManager.addLayer(chooseCategory(),
>>                    dataSourceQuery.toString(), dataset).setDataSourceQuery(
>>                    dataSourceQuery).setFeatureCollectionModified(false);
>>            }
>>        } finally {
>>            connection.close();
>>        }
>>        if (!exceptions.isEmpty()) {
>>            WorkbenchFrame workbenchFrame = workbenchContext.getWorkbench()
>>                .getFrame();
>>            HTMLFrame outputFrame = workbenchFrame.getOutputFrame();
>>            outputFrame.createNewDocument();
>>            reportExceptions(exceptions, dataSourceQuery, workbenchFrame,
>>                outputFrame);
>>            workbenchFrame.warnUser(I18N
>>                
>> .get("datasource.LoadDatasetPlugIn.problems-were-encountered"));
>>        }
>>
>>        return false;
>>    }
>>
>>    protected Map<String, Object> toProperties(URI uri,
>>        Map<String, Object> options) {
>>        Map<String, Object> properties = new HashMap<String, Object>();
>>        File file;
>>        if (uri.getScheme().equals("zip")) {
>>            file = UriUtil.getZipFile(uri);
>>            String compressedFile = UriUtil.getZipEntryName(uri);
>>            properties.put("CompressedFile", compressedFile);
>>        } else {
>>            file = new File(uri);
>>        }
>>        String filePath = file.getAbsolutePath();
>>        properties.put(DataSource.FILE_KEY, filePath);
>>        properties.putAll(options);
>>        return properties;
>>    }
>>
>>    private void reportExceptions(ArrayList exceptions,
>>        DataSourceQuery dataSourceQuery, WorkbenchFrame workbenchFrame,
>>        HTMLFrame outputFrame) {
>>        outputFrame.addHeader(1, exceptions.size()
>>            + " "
>>            + I18N.get("datasource.LoadDatasetPlugIn.problem")
>>            + StringUtil.s(exceptions.size())
>>            + " "
>>            + I18N.get("datasource.LoadDatasetPlugIn.loading")
>>            + " "
>>            + dataSourceQuery.toString()
>>            + "."
>>            + ((exceptions.size() > 10) ? I18N
>>                .get("datasource.LoadDatasetPlugIn.first-and-last-five") : 
>> ""));
>>        outputFrame.addText(I18N
>>            .get("datasource.LoadDatasetPlugIn.see-view-log"));
>>        outputFrame.append("<ul>");
>>
>>        Collection exceptionsToReport = exceptions.size() <= 10 ? exceptions
>>            : CollectionUtil.concatenate(Arrays.asList(new Collection[] {
>>                exceptions.subList(0, 5),
>>                exceptions.subList(exceptions.size() - 5, exceptions.size())
>>            }));
>>        for (Iterator j = exceptionsToReport.iterator(); j.hasNext();) {
>>            Exception exception = (Exception)j.next();
>>            workbenchFrame.log(StringUtil.stackTrace(exception));
>>            outputFrame.append("<li>");
>>            outputFrame.append(GUIUtil.escapeHTML(WorkbenchFrame
>>                .toMessage(exception), true, true));
>>            outputFrame.append("</li>");
>>            exception.printStackTrace();
>>        }
>>        outputFrame.append("</ul>");
>>    }
>>
>>    private String chooseCategory() {
>>        LayerNamePanel layerNamePanel = workbenchContext.getLayerNamePanel();
>>        Collection selectedCategories = 
>> layerNamePanel.getSelectedCategories();
>>        if (selectedCategories.isEmpty()) {
>>            return StandardCategoryNames.WORKING;
>>        } else {
>>            return selectedCategories.iterator().next().toString();
>>        }
>>    }
>> }
>>  
>>
>> ------------------------------------------------------------------------
>>
>> package com.revolsys.jump.ui.file;
>>
>> import java.awt.Color;
>> import java.io.File;
>> import java.io.FileOutputStream;
>> import java.io.IOException;
>> import java.io.InputStream;
>> import java.net.URI;
>> import java.nio.channels.Channels;
>> import java.nio.channels.FileChannel;
>> import java.nio.channels.ReadableByteChannel;
>> import java.util.Arrays;
>> import java.util.Collection;
>> import java.util.Map;
>> import java.util.zip.ZipEntry;
>> import java.util.zip.ZipFile;
>>
>> import com.revolsys.io.FileUtil;
>> import com.vividsolutions.jts.geom.Coordinate;
>> import com.vividsolutions.jts.geom.GeometryFactory;
>> import com.vividsolutions.jump.feature.BasicFeature;
>> import com.vividsolutions.jump.feature.Feature;
>> import com.vividsolutions.jump.feature.FeatureDataset;
>> import com.vividsolutions.jump.task.TaskMonitor;
>> import com.vividsolutions.jump.workbench.WorkbenchContext;
>> import com.vividsolutions.jump.workbench.imagery.ImageryLayerDataset;
>> import com.vividsolutions.jump.workbench.imagery.ReferencedImageFactory;
>> import com.vividsolutions.jump.workbench.imagery.ReferencedImageStyle;
>> import com.vividsolutions.jump.workbench.model.Layer;
>> import com.vividsolutions.jump.workbench.model.LayerManager;
>> import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
>> import com.vividsolutions.jump.workbench.ui.LayerNamePanel;
>>
>> public class ReferencedImageFactoryFileLoader extends AbstractFileLoader {
>>    private Class dataSourceClass;
>>
>>    private WorkbenchContext workbenchContext;
>>
>>    private ReferencedImageFactory imageFactory;
>>
>>    private String[] supportFileExtensions;
>>
>>    public ReferencedImageFactoryFileLoader(WorkbenchContext workbenchContext,
>>        ReferencedImageFactory imageFactory, String[] supportFileExtensions) {
>>        super(imageFactory.getDescription(), Arrays.asList(imageFactory
>>            .getExtensions()));
>>        this.imageFactory = imageFactory;
>>        this.workbenchContext = workbenchContext;
>>        this.supportFileExtensions = supportFileExtensions;
>>    }
>>
>>    public boolean open(TaskMonitor monitor, URI uri,
>>        Map<String, Object> options) {
>>        File file;
>>        if (uri.getScheme().equals("zip")) {
>>            try {
>>                File zipFileName = UriUtil.getZipFile(uri);
>>                String entryPath = UriUtil.getZipEntryFilePath(uri);
>>                String entryFileName = UriUtil.getFileName(uri);
>>                String entryBaseName = 
>> UriUtil.getFileNameWithoutExtension(uri);
>>                ZipFile zipFile = new ZipFile(zipFileName);
>>                try {
>>                    monitor.report("Decompressing: " + entryFileName);
>>                    file = unzip(zipFile, entryPath, entryFileName);
>>                    if (supportFileExtensions != null) {
>>                        for (String extension : supportFileExtensions) {
>>                            monitor.report("Decompressing: " + entryBaseName
>>                                + "." + extension);
>>                            unzip(zipFile, entryPath, entryBaseName + "."
>>                                + extension);
>>                        }
>>                    }
>>                } finally {
>>                    zipFile.close();
>>                }
>>            } catch (Exception e) {
>>                monitor.report(e);
>>                return false;
>>            }
>>        } else {
>>            file = new File(uri);
>>        }
>>        LayerManager layerManager = workbenchContext.getLayerManager();
>>
>>        layerManager.setFiringEvents(false);
>>        Layer layer = createLayer(layerManager, file);
>>        layerManager.setFiringEvents(true);
>>
>>        layerManager.addLayer(chooseCategory(), layer);
>>        Feature feature = createFeature(imageFactory, file,
>>            getImageryLayerDataset(layer));
>>        layer.getFeatureCollectionWrapper().add(feature);
>>        String imageFilePath = (String)feature
>>            .getAttribute(ImageryLayerDataset.ATTR_FILE);
>>        if (imageFactory.isEditableImage(imageFilePath)) {
>>            layer.setSelectable(true);
>>            layer.setEditable(true);
>>            layer.setReadonly(false);
>>        } else {
>>            layer.setSelectable(false);
>>            layer.setEditable(false);
>>            layer.setReadonly(true);
>>        }
>>        return true;
>>    }
>>
>>    private File unzip(ZipFile zipFile, String path, String name)
>>        throws IOException {
>>        String entryName;
>>        if (path != null) {
>>            entryName = path + "/" + name;
>>        } else {
>>            entryName = name;
>>        }
>>        ZipEntry entry = zipFile.getEntry(entryName);
>>        if (entry != null) {
>>            File file = new File(System.getProperty("java.io.tmpdir"), name);
>>            file.deleteOnExit();
>>            InputStream in = zipFile.getInputStream(entry);
>>
>>            ReadableByteChannel rc = null;
>>            FileOutputStream out = null;
>>
>>            try {
>>                rc = Channels.newChannel(in);
>>                out = new FileOutputStream(file);
>>                FileChannel fc = out.getChannel();
>>
>>                // read into the buffer
>>                long count = 0;
>>                int attempts = 0;
>>                long sz = entry.getSize();
>>                while (count < sz) {
>>                    long written = fc.transferFrom(rc, count, sz);
>>                    count += written;
>>
>>                    if (written == 0) {
>>                        attempts++;
>>                        if (attempts > 100) {
>>                            throw new IOException("Error writing to file "
>>                                + file);
>>                        }
>>                    } else {
>>                        attempts = 0;
>>                    }
>>                }
>>
>>                out.close();
>>                out = null;
>>            } finally {
>>                if (out != null) {
>>                    try {
>>                        out.close();
>>                    } catch (Exception ex) {
>>                    }
>>                }
>>            }
>>            return file;
>>        } else {
>>            return null;
>>        }
>>
>>    }
>>
>>    private ImageryLayerDataset getImageryLayerDataset(Layer layer) {
>>        ReferencedImageStyle irs = (ReferencedImageStyle)layer
>>            .getStyle(ReferencedImageStyle.class);
>>        return irs.getImageryLayerDataset();
>>    }
>>
>>    private Feature createFeature(
>>        ReferencedImageFactory referencedImageFactory, File file,
>>        ImageryLayerDataset imageryLayerDataset) {
>>
>>        Feature feature = new BasicFeature(ImageryLayerDataset.getSchema());
>>        feature.setAttribute(ImageryLayerDataset.ATTR_FILE, file.getPath());
>>        feature.setAttribute(ImageryLayerDataset.ATTR_FORMAT,
>>            referencedImageFactory.getTypeName());
>>        feature.setAttribute(ImageryLayerDataset.ATTR_FACTORY,
>>            referencedImageFactory.getClass().getName());
>>        feature
>>            .setGeometry(new GeometryFactory().createPoint((Coordinate)null));
>>        imageryLayerDataset.createImage(feature);
>>        return feature;
>>    }
>>
>>    private Layer createLayer(LayerManager layerManager, File file) {
>>        Layer layer = new Layer(file.getName(), Color.black,
>>            new FeatureDataset(ImageryLayerDataset.getSchema()), 
>> layerManager);
>>        layer.setEditable(true);
>>        layer.getBasicStyle().setEnabled(false);
>>        layer.getBasicStyle().setRenderingFill(false);
>>        layer.addStyle(new ReferencedImageStyle());
>>        return layer;
>>    }
>>
>>    private String chooseCategory() {
>>        LayerNamePanel layerNamePanel = workbenchContext.getLayerNamePanel();
>>        Collection selectedCategories = 
>> layerNamePanel.getSelectedCategories();
>>        if (selectedCategories.isEmpty()) {
>>            return StandardCategoryNames.WORKING;
>>        } else {
>>            return selectedCategories.iterator().next().toString();
>>        }
>>    }
>> }
>>  
>>
>> ------------------------------------------------------------------------
>>
>> package com.revolsys.jump.ui.file;
>>
>> import java.util.ArrayList;
>> import java.util.Collection;
>> import java.util.List;
>>
>> public abstract class AbstractFileLoader implements FileLoader {
>>
>>    private String description;
>>
>>    private List<String> extensions;
>>    
>>    private List<Option> optionMetadata = new ArrayList<Option>();
>>
>>    public AbstractFileLoader() {
>>    }
>>
>>    public AbstractFileLoader(final String description, final List<String> 
>> extensions) {
>>        this.description = description;
>>        this.extensions = extensions;
>>    }
>>
>>    public String getDescription() {
>>        return description;
>>    }
>>
>>    public Collection<String> getFileExtensions() {
>>        return extensions;
>>    }
>>
>>    public String toString() {
>>        return description;
>>    }
>>
>>    public void addOptionField(String name, String type, boolean required) {
>>      optionMetadata.add(new Option(name, type, required));
>>    }
>>    public List<Option> getOptionMetadata() {
>>        return optionMetadata;
>>    }
>>
>> }
>>  
>>
>> ------------------------------------------------------------------------
>>
>> -------------------------------------------------------------------------
>> This SF.net email is sponsored by: Splunk Inc.
>> Still grepping through log files to find problems?  Stop.
>> Now Search log events and configuration files using AJAX and a browser.
>> Download your FREE copy of Splunk now >>  http://get.splunk.com/
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Jump-pilot-devel mailing list
>> Jump-pilot-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>  
>>
>>     
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems?  Stop.
> Now Search log events and configuration files using AJAX and a browser.
> Download your FREE copy of Splunk now >>  http://get.splunk.com/
> _______________________________________________
> Jump-pilot-devel mailing list
> Jump-pilot-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>   



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to