Search in sources :

Example 1 with ZipLeveledStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider in project tdi-studio-se by Talend.

the class ImportItemWizardPage method updateItemsList.

public void updateItemsList(final String path, boolean isneedUpdate) {
    if (!isneedUpdate) {
        if (path.equals(lastPath)) {
            return;
        }
    }
    lastPath = path;
    if (path == null || path.length() == 0) {
        selectedItems = new ArrayList<ItemRecord>();
        checkTreeViewer.refresh(true);
        // get the top item to check if tree is empty, if not then uncheck everything
        TreeItem topItem = checkTreeViewer.getTree().getTopItem();
        if (topItem != null) {
            checkTreeViewer.setSubtreeChecked(topItem.getData(), false);
        }
        // else not root element, tree is already empty
        checkValidItems();
        return;
    }
    final boolean dirSelected = this.itemFromDirectoryRadio.getSelection();
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) {
                // monitor.beginTask(DataTransferMessages.WizardProjectsImportPage_SearchingMessage, 100);
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("DataTransferMessages.WizardProjectsImportPage_SearchingMessage"), 100);
                File directory = new File(path);
                monitor.worked(10);
                if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
                    sourceTarFile = getSpecifiedTarSourceFile(path);
                    if (sourceTarFile == null) {
                        return;
                    }
                    TarLeveledStructureProvider provider = new TarLeveledStructureProvider(sourceTarFile);
                    manager = ResourcesManagerFactory.getInstance().createResourcesManager(provider);
                    if (!manager.collectPath2Object(provider.getRoot())) {
                        return;
                    }
                } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
                    sourceFile = getSpecifiedZipSourceFile(path);
                    if (sourceFile == null) {
                        return;
                    }
                    ZipLeveledStructureProvider provider = new ZipLeveledStructureProvider(sourceFile);
                    manager = ResourcesManagerFactory.getInstance().createResourcesManager(provider);
                    if (!manager.collectPath2Object(provider.getRoot())) {
                        return;
                    }
                } else if (dirSelected && directory.isDirectory()) {
                    manager = ResourcesManagerFactory.getInstance().createResourcesManager();
                    if (!manager.collectPath2Object(directory)) {
                        return;
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        IDEWorkbenchPlugin.log(e.getMessage(), e);
    } catch (InterruptedException e) {
    // Nothing to do if the user interrupts.
    }
    populateItems();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) TreeItem(org.eclipse.swt.widgets.TreeItem) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 2 with ZipLeveledStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider in project tdi-studio-se by Talend.

the class ImportProjectsUtilities method importArchiveProject.

public static void importArchiveProject(Shell shell, String technicalName, String sourcePath, IProgressMonitor monitor) throws InvocationTargetException, InterruptedException, TarException, IOException {
    IImportStructureProvider provider;
    Object source;
    if (ArchiveFileManipulations.isZipFile(sourcePath)) {
        ZipLeveledStructureProvider zipProvider = new ZipLeveledStructureProvider(new ZipFile(sourcePath));
        source = zipProvider.getRoot();
        boolean ok = true;
        for (Object o : zipProvider.getChildren(source)) {
            String label = zipProvider.getLabel(o);
            if (!label.equals(IProjectDescription.DESCRIPTION_FILE_NAME) && ok) {
                source = o;
            } else {
                ok = false;
            }
        }
        if (!ok) {
            source = zipProvider.getRoot();
        }
        provider = zipProvider;
    } else if (ArchiveFileManipulations.isTarFile(sourcePath)) {
        TarLeveledStructureProvider tarProvider = new TarLeveledStructureProvider(new TarFile(sourcePath));
        source = tarProvider.getRoot();
        boolean ok = true;
        for (Object o : tarProvider.getChildren(source)) {
            String label = tarProvider.getLabel(o);
            if (!label.equals(IProjectDescription.DESCRIPTION_FILE_NAME) && ok) {
                source = o;
            } else {
                ok = false;
            }
        }
        if (!ok) {
            source = tarProvider.getRoot();
        }
        provider = tarProvider;
    } else {
        //$NON-NLS-1$
        throw new IllegalArgumentException(Messages.getString("ImportProjectsUtilities.fileFormatError", sourcePath));
    }
    importProject(shell, provider, source, new Path(technicalName), false, false, monitor);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IImportStructureProvider(org.eclipse.ui.wizards.datatransfer.IImportStructureProvider)

Example 3 with ZipLeveledStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider in project tdi-studio-se by Talend.

the class ImportProjectAsWizardPage method evaluateSpecifiedPath.

private void evaluateSpecifiedPath(String path) {
    if (path.equals(lastPath)) {
        return;
    }
    // on an empty path empty selectedProjects
    if (path == null || path.length() == 0) {
        checkFieldsValue();
        return;
    }
    final boolean dirSelected = this.projectFromDirectoryRadio.getSelection();
    File directory = new File(path);
    Collection projectFiles = new ArrayList();
    Collection talendProjectFiles = new ArrayList();
    if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
        TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
        if (sourceTarFile == null) {
            return;
        }
        TarLeveledStructureProvider provider = new TarLeveledStructureProvider(sourceTarFile);
        Object child = provider.getRoot();
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(projectFiles, provider, child, 0, null, IProjectDescription.DESCRIPTION_FILE_NAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(talendProjectFiles, provider, child, 0, null, FileConstants.LOCAL_PROJECT_FILENAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(talendProjectFiles, provider, child, 0, null, FileConstants.OLD_TALEND_PROJECT_FILENAME)) {
            return;
        }
    } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
        ZipFile sourceFile = getSpecifiedZipSourceFile(path);
        if (sourceFile == null) {
            return;
        }
        ZipLeveledStructureProvider provider = new ZipLeveledStructureProvider(sourceFile);
        Object child = provider.getRoot();
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(projectFiles, provider, child, 0, null, IProjectDescription.DESCRIPTION_FILE_NAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(talendProjectFiles, provider, child, 0, null, FileConstants.LOCAL_PROJECT_FILENAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromProvider(talendProjectFiles, provider, child, 0, null, FileConstants.OLD_TALEND_PROJECT_FILENAME)) {
            return;
        }
    } else if (dirSelected && directory.isDirectory()) {
        if (!ImportProjectsUtilities.collectProjectFilesFromDirectory(projectFiles, directory, null, IProjectDescription.DESCRIPTION_FILE_NAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromDirectory(talendProjectFiles, directory, null, FileConstants.LOCAL_PROJECT_FILENAME)) {
            return;
        }
        if (!ImportProjectsUtilities.collectProjectFilesFromDirectory(talendProjectFiles, directory, null, FileConstants.OLD_TALEND_PROJECT_FILENAME)) {
            return;
        }
    }
    lastPath = path;
    if (projectFiles.size() != 1 || talendProjectFiles.size() != 1) {
        IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
        String string = //$NON-NLS-1$
        Messages.getString(//$NON-NLS-1$
        "ImportProjectAsWizardPage.error.notATalendProject", brandingService.getShortProductName());
        fileContentStatus = new Status(IStatus.ERROR, RepositoryPlugin.PLUGIN_ID, IStatus.OK, string, null);
    } else {
        fileContentStatus = createOkStatus();
    }
    checkFieldsValue();
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) Collection(java.util.Collection) IBrandingService(org.talend.core.ui.branding.IBrandingService) ZipFile(java.util.zip.ZipFile) File(java.io.File) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile)

Example 4 with ZipLeveledStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider in project tdi-studio-se by Talend.

the class TalendWizardProjectsImportPage method getProjectRecords.

@Override
public ProjectRecord[] getProjectRecords() {
    if (sourcePath == null || sourcePath.length() == 0) {
        return new ProjectRecord[0];
    }
    ProjectRecord[] selectedProjects = super.getProjectRecords();
    Collection files = new ArrayList();
    List projects = new ArrayList();
    ProjectRecord[] selected = null;
    for (ProjectRecord selectedProject : selectedProjects) {
        projects.add(selectedProject);
    }
    final File directory = new File(sourcePath);
    if (ArchiveFileManipulations.isTarFile(sourcePath)) {
        try {
            TarFile sourceTarFile = new TarFile(sourcePath);
            if (sourceTarFile == null) {
                return new ProjectRecord[0];
            }
            structureProvider = new TarLeveledStructureProvider(sourceTarFile);
            Object child = structureProvider.getRoot();
            collectProjectFilesFromProvider(files, child, 0);
            selected = new ProjectRecord[files.size()];
            Iterator filesIterator = files.iterator();
            int j = 0;
            while (filesIterator.hasNext()) {
                TalendProjectRecord file = (TalendProjectRecord) filesIterator.next();
                for (int i = 0; i < projects.size(); i++) {
                    if (file.getProjectName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                        selected[j] = (ProjectRecord) projects.get(i);
                        j++;
                    }
                }
            }
        } catch (TarException e) {
            // displayErrorDialog(DataTransferMessages.TarImport_badFormat);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.TarImport_badFormat"));
        } catch (IOException e) {
            // displayErrorDialog(DataTransferMessages.ZipImport_couldNotRead);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.ZipImport_couldNotRead"));
        }
    } else if (ArchiveFileManipulations.isZipFile(sourcePath)) {
        try {
            ZipFile sourceFile = new ZipFile(sourcePath);
            if (sourceFile == null) {
                return new ProjectRecord[0];
            }
            structureProvider = new ZipLeveledStructureProvider(sourceFile);
            Object child = structureProvider.getRoot();
            collectProjectFilesFromProvider(files, child, 0);
            selected = new ProjectRecord[files.size()];
            Iterator filesIterator = files.iterator();
            int j = 0;
            while (filesIterator.hasNext()) {
                TalendProjectRecord file = (TalendProjectRecord) filesIterator.next();
                for (int i = 0; i < projects.size(); i++) {
                    if (file.getProjectName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                        selected[j] = (ProjectRecord) projects.get(i);
                        j++;
                    }
                }
            }
        } catch (IOException e) {
            // displayErrorDialog(DataTransferMessages.ZipImport_badFormat);
            //$NON-NLS-1$
            displayErrorDialog(Messages.getString("DataTransferMessages.ZipImport_badFormat"));
        }
    } else if (directory.isDirectory()) {
        collectProjectFilesFromDirectory(files, directory, null);
        selected = new ProjectRecord[files.size()];
        Iterator filesIterator = files.iterator();
        int j = 0;
        while (filesIterator.hasNext()) {
            File file = (File) filesIterator.next();
            for (int i = 0; i < projects.size(); i++) {
                if (file.getParentFile().getName().equals(((ProjectRecord) projects.get(i)).getProjectName())) {
                    selected[j] = (ProjectRecord) projects.get(i);
                    j++;
                }
            }
        }
    }
    return selected;
}
Also used : TarException(org.eclipse.ui.internal.wizards.datatransfer.TarException) ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) ZipFile(java.util.zip.ZipFile) File(java.io.File) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile)

Example 5 with ZipLeveledStructureProvider

use of org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider in project translationstudio8 by heartsome.

the class ImportProjectWizardPage2 method updateProjectsList.

public void updateProjectsList(final String path) {
    if (path == null || path.length() == 0) {
        setMessage(Messages.getString("wizard.ImportProjectWizardPage.desc"));
        selectedProjects = new ProjectRecord[0];
        setPageComplete(selectElementTree.getCheckedElements().length > 0);
        lastPath = path;
        return;
    }
    final File directory = new File(path);
    long modified = directory.lastModified();
    if (path.equals(lastPath) && lastModified == modified && lastCopyFiles == copyFiles) {
        // change, no refreshing is required
        return;
    }
    lastPath = path;
    lastModified = modified;
    lastCopyFiles = copyFiles;
    // We can't access the radio button from the inner class so get the
    // status beforehand
    final boolean dirSelected = false;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @SuppressWarnings({ "rawtypes", "restriction" })
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Messages.getString("importProjectWizardPage.searchingMessage"), 100);
                selectedProjects = new ProjectRecord[0];
                Collection files = new ArrayList();
                monitor.worked(10);
                if (!dirSelected && ArchiveFileManipulations.isTarFile(path)) {
                    TarFile sourceTarFile = getSpecifiedTarSourceFile(path);
                    if (sourceTarFile == null) {
                        return;
                    }
                    structureProvider = new TarLeveledStructureProvider(sourceTarFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else if (!dirSelected && ArchiveFileManipulations.isZipFile(path)) {
                    ZipFile sourceFile = getSpecifiedZipSourceFile(path);
                    if (sourceFile == null) {
                        return;
                    }
                    structureProvider = new ZipLeveledStructureProvider(sourceFile);
                    Object child = structureProvider.getRoot();
                    if (!collectProjectFilesFromProvider(files, child, 0, monitor)) {
                        return;
                    }
                    Iterator filesIterator = files.iterator();
                    selectedProjects = new ProjectRecord[files.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(Messages.getString("importProjectWizardPage.processingMessage"));
                    while (filesIterator.hasNext()) {
                        selectedProjects[index++] = (ProjectRecord) filesIterator.next();
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (InterruptedException e) {
        LOGGER.error(e.getMessage(), e);
    }
    // 开始处理导入项目中的项目名称不合法的情况
    String projectName = "";
    StringBuffer errorProjectNameSB = new StringBuffer();
    StringBuffer errorCharSB = new StringBuffer();
    List<ProjectRecord> tempList = new ArrayList<ProjectRecord>();
    boolean isError = false;
    for (int i = 0; i < selectedProjects.length; i++) {
        projectName = selectedProjects[i].getProjectName();
        isError = false;
        for (int j = 0; j < Constant.RESOURCE_ERRORCHAR.length; j++) {
            if (projectName.indexOf(Constant.RESOURCE_ERRORCHAR[j]) != -1) {
                errorCharSB.append(Constant.RESOURCE_ERRORCHAR[j]);
                errorProjectNameSB.append(projectName + ", ");
                isError = true;
            }
        }
        if (!isError) {
            tempList.add(selectedProjects[i]);
        }
    }
    if (errorProjectNameSB.length() > 0) {
        final String errorTip = MessageFormat.format(Messages.getString("importProjectWizardPage.projectError"), new Object[] { errorProjectNameSB.toString().substring(0, errorProjectNameSB.toString().length() - 2), errorCharSB.toString() });
        Display.getDefault().asyncExec(new Runnable() {

            public void run() {
                MessageDialog.openWarning(getShell(), Messages.getString("importProject.all.dialog.warning"), errorTip);
            }
        });
    }
    selectedProjects = tempList.toArray(new ProjectRecord[tempList.size()]);
    setPageComplete(selectElementTree.getCheckedElements().length > 0);
    selectElementTree.refresh(true);
}
Also used : ZipLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) TarLeveledStructureProvider(org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) Iterator(java.util.Iterator) Collection(java.util.Collection) ZipFile(java.util.zip.ZipFile) TarFile(org.eclipse.ui.internal.wizards.datatransfer.TarFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

ZipFile (java.util.zip.ZipFile)7 TarFile (org.eclipse.ui.internal.wizards.datatransfer.TarFile)7 TarLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.TarLeveledStructureProvider)7 ZipLeveledStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ZipLeveledStructureProvider)7 File (java.io.File)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 Iterator (java.util.Iterator)3 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IOException (java.io.IOException)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 ILeveledImportStructureProvider (org.eclipse.ui.internal.wizards.datatransfer.ILeveledImportStructureProvider)1