Java 类org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider 实例源码

项目:Environment    文件:ExampleService.java   
public static IProject unpackResourceProject(IProject project, Example.Resource resource) throws Exception
{
    if (resource.getType() == Type.ENVIRONMENT)
        CloudScaleProjectSupport.addProjectNature(project);

    ZipFile file = new ZipFile(resource.getArchive().getFile());
    ZipFileStructureProvider provider = new ZipFileStructureProvider(file);
    IPath containerPath = project.getFullPath();
    Object source = provider.getRoot();

    IOverwriteQuery query = new IOverwriteQuery()
    {
        @Override
        public String queryOverwrite(String path)
        {
            return IOverwriteQuery.ALL;
        };
    };
    ImportOperation operation = new ImportOperation(containerPath, source, provider, query);
    operation.run(null);

    return project;
}
项目:birt    文件:BirtWizardUtil.java   
/**
 * extract zip file and import files into project
 * 
 * @param srcZipFile
 * @param destPath
 * @param monitor
 * @param query
 * @throws CoreException
 */
private static void importFilesFromZip( ZipFile srcZipFile, IPath destPath,
        IProgressMonitor monitor, IOverwriteQuery query )
        throws CoreException
{
    try
    {
        ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(
                srcZipFile );
        List list = prepareFileList( structureProvider, structureProvider
                .getRoot( ), null );
        ImportOperation op = new ImportOperation( destPath,
                structureProvider.getRoot( ), structureProvider, query,
                list );
        op.run( monitor );
    }
    catch ( Exception e )
    {
        String message = srcZipFile.getName( ) + ": " + e.getMessage( ); //$NON-NLS-1$
        Logger.logException( e );
        throw BirtCoreException.getException( message, e );
    }
}
项目:eclipseRecorder    文件:SnapshotManagerTest.java   
private void assertEntryMatchesDir(ZipFileStructureProvider structureProvider, IContainer folder, ZipEntry parentEntry) throws Exception {
    List unexportedItems = Arrays.asList("bin");
    IResource[] members = folder.members();
    List children = structureProvider.getChildren(parentEntry);
    for (IResource member : members) {
        String memberName = member.getName();
        if (unexportedItems.contains(memberName))
            continue;
        boolean found = false;
        for (Object child : children) {
            ZipEntry entry = (ZipEntry) child;
            String entryName = getEntryName(entry);
            if (entryName.equals(memberName)) {
                found = true;
                if (member instanceof IFolder)
                    if (entry.isDirectory())
                        assertEntryMatchesDir(structureProvider, (IContainer) member, entry);
                    else
                        fail("Directories don't match");
            }
        } 
        assertTrue(found);
    }
}
项目:Environment    文件:ExampleProjectWizard.java   
public static IProject createExampleProject(IProject project, Example.Resource resource)
{
    try
    {

        if (resource.getType() == Type.ENVIRONMENT)
            CloudScaleProjectSupport.addProjectNature(project);

        ZipFile file = new ZipFile(resource.getArchive().getFile());
        ZipFileStructureProvider provider = new ZipFileStructureProvider(file);
        IPath containerPath = project.getFullPath();
        Object source = provider.getRoot();

        IOverwriteQuery query = new IOverwriteQuery()
        {
            @Override
            public String queryOverwrite(String path)
            {
                return IOverwriteQuery.ALL;
            };
        };
        ImportOperation operation = new ImportOperation(containerPath, source, provider, query);
        try
        {
            operation.run(null);
        } catch (Exception ex)
        {
            ex.printStackTrace();
        }
    } catch (Exception e)
    {
        e.printStackTrace();
        project = null;
    }

    return project;
}
项目:fb-contrib-eclipse-quick-fixes    文件:JavaProjectHelper.java   
public static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor)
        throws InvocationTargetException {
    ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(srcZipFile);
    try {
        ImportOperation op = new ImportOperation(destPath, structureProvider.getRoot(), structureProvider,
                new ImportOverwriteQuery());
        op.run(monitor);
    } catch (InterruptedException e) {
        // should not happen
    }
}
项目:birt    文件:BirtWizardUtil.java   
/**
 * Prepare file list from zip file
 * 
 * @param structure
 * @param entry
 * @param list
 * @return
 */
private static List prepareFileList( ZipFileStructureProvider structure,
        ZipEntry entry, List list )
{
    if ( structure == null || entry == null )
        return null;

    if ( list == null )
    {
        list = new ArrayList( );
    }

    // get children
    List son = structure.getChildren( entry );
    if ( son == null )
        return list;

    // check if directory
    Iterator it = son.iterator( );
    while ( it.hasNext( ) )
    {
        ZipEntry temp = (ZipEntry) it.next( );
        if ( temp.isDirectory( ) )
        {
            prepareFileList( structure, temp, list );
        }
        else
        {
            // if it is file, add to list
            list.add( temp );
        }
    }

    return list;
}
项目:birt    文件:BirtWizardUtil.java   
/**
 * Prepare file list from zip file
 * 
 * @param structure
 * @param entry
 * @param list
 * @return
 */
private static List prepareFileList( ZipFileStructureProvider structure,
        ZipEntry entry, List list )
{
    if ( structure == null || entry == null )
        return null;

    if ( list == null )
    {
        list = new ArrayList( );
    }

    // get children
    List son = structure.getChildren( entry );
    if ( son == null )
        return list;

    // check if directory
    Iterator it = son.iterator( );
    while ( it.hasNext( ) )
    {
        ZipEntry temp = (ZipEntry) it.next( );
        if ( temp.isDirectory( ) )
        {
            prepareFileList( structure, temp, list );
        }
        else
        {
            // if it is file, add to list
            list.add( temp );
        }
    }

    return list;
}
项目:eclipseRecorder    文件:SnapshotManagerTest.java   
@Test
public void testCompleteSnapshot() throws Exception {
    String snapshotFile = snapshotManager.takeSnapshot(javaProject.getProject());
    Thread.sleep(200);
    ZipFileStructureProvider structureProvider = new ZipFileStructureProvider(new ZipFile(snapshotFile));
    ZipEntry rootEntry = structureProvider.getRoot();

    List children = structureProvider.getChildren(rootEntry);
    ZipEntry projectRoot = getProjectEntry(children);
    assertEntryMatchesDir(structureProvider, javaProject.getProject(), projectRoot);
}
项目:Eclipse-Postfix-Code-Completion    文件:JavadocConfigurationBlock.java   
private String internalChooseArchivePath() {
    ZipFile zipFile= null;
    try {
        if (fWorkspaceRadio.isSelected()) {
            IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(fArchiveField.getText()));
            if (resource != null) {
                IPath location= resource.getLocation();
                if (location != null) {
                    zipFile= new ZipFile(location.toOSString());
                }
            }
        } else {
            zipFile= new ZipFile(fArchiveField.getText());
        }
        if (zipFile == null) {
            return null;
        }

        ZipFileStructureProvider provider= new ZipFileStructureProvider(zipFile);

        ILabelProvider lp= new ZipDialogLabelProvider(provider);
        ZipDialogContentProvider cp= new ZipDialogContentProvider(provider);

        ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(fShell, lp, cp);
        dialog.setAllowMultiple(false);
        dialog.setValidator(new ZipDialogValidator());
        dialog.setTitle(PreferencesMessages.JavadocConfigurationBlock_browse_jarorzip_path_title);
        dialog.setMessage(PreferencesMessages.JavadocConfigurationBlock_location_in_jarorzip_message);
        dialog.setComparator(new ViewerComparator());

        String init= fArchivePathField.getText();
        if (init.length() == 0) {
            init= "docs/api"; //$NON-NLS-1$
        }
        dialog.setInitialSelection(cp.findElement(new Path(init)));

        dialog.setInput(this);
        if (dialog.open() == Window.OK) {
            String name= provider.getFullPath(dialog.getFirstResult());
            return new Path(name).removeTrailingSeparator().toString();
        }
    } catch (IOException e) {
        JavaPlugin.log(e);
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException e1) {
                // ignore
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavadocConfigurationBlock.java   
public ZipDialogContentProvider(ZipFileStructureProvider provider) {
    fProvider= provider;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavadocConfigurationBlock.java   
public ZipDialogLabelProvider(ZipFileStructureProvider provider) {
    fProvider= provider;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocConfigurationBlock.java   
private String internalChooseArchivePath() {
    ZipFile zipFile= null;
    try {
        if (fWorkspaceRadio.isSelected()) {
            IResource resource= ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(fArchiveField.getText()));
            if (resource != null) {
                IPath location= resource.getLocation();
                if (location != null) {
                    zipFile= new ZipFile(location.toOSString());
                }
            }
        } else {
            zipFile= new ZipFile(fArchiveField.getText());
        }
        if (zipFile == null) {
            return null;
        }

        ZipFileStructureProvider provider= new ZipFileStructureProvider(zipFile);

        ILabelProvider lp= new ZipDialogLabelProvider(provider);
        ZipDialogContentProvider cp= new ZipDialogContentProvider(provider);

        ElementTreeSelectionDialog dialog= new ElementTreeSelectionDialog(fShell, lp, cp);
        dialog.setAllowMultiple(false);
        dialog.setValidator(new ZipDialogValidator());
        dialog.setTitle(PreferencesMessages.JavadocConfigurationBlock_browse_jarorzip_path_title);
        dialog.setMessage(PreferencesMessages.JavadocConfigurationBlock_location_in_jarorzip_message);
        dialog.setComparator(new ViewerComparator());

        String init= fArchivePathField.getText();
        if (init.length() == 0) {
            init= "docs/api"; //$NON-NLS-1$
        }
        dialog.setInitialSelection(cp.findElement(new Path(init)));

        dialog.setInput(this);
        if (dialog.open() == Window.OK) {
            String name= provider.getFullPath(dialog.getFirstResult());
            return new Path(name).removeTrailingSeparator().toString();
        }
    } catch (IOException e) {
        JavaPlugin.log(e);
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException e1) {
                // ignore
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocConfigurationBlock.java   
public ZipDialogContentProvider(ZipFileStructureProvider provider) {
    fProvider= provider;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavadocConfigurationBlock.java   
public ZipDialogLabelProvider(ZipFileStructureProvider provider) {
    fProvider= provider;
}