Search in sources :

Example 1 with SelectDeleteProjectDialog

use of org.talend.repository.ui.actions.importproject.SelectDeleteProjectDialog in project tdi-studio-se by Talend.

the class TOSLoginComposite method addListener.

private void addListener() {
    createButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Project project = null;
            ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
            NewProjectWizard newPrjWiz = new NewProjectWizard(null);
            WizardDialog newProjectDialog = new WizardDialog(getShell(), newPrjWiz);
            //$NON-NLS-1$
            newProjectDialog.setTitle(Messages.getString("LoginDialog.newProjectTitle"));
            if (newProjectDialog.open() == Window.OK) {
                project = newPrjWiz.getProject();
                refresh();
                ArrayList<String> allProjects = (ArrayList<String>) projectListViewer.getInput();
                int index = 0;
                Collections.sort(allProjects);
                for (int i = 0; i < allProjects.size(); i++) {
                    String projectName = allProjects.get(i);
                    if (project.getLabel().equals(projectName)) {
                        index = i;
                        break;
                    }
                }
                projectListViewer.getList().select(index);
                projectListViewer.refresh();
            }
        }
    });
    deleteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Shell activeShell = Display.getCurrent().getActiveShell();
            SelectDeleteProjectDialog dialog = new SelectDeleteProjectDialog(activeShell, true);
            if (dialog.open() == Dialog.OK) {
                CorePlugin.getDefault().getRepositoryLocalProviderService().resetXmiResourceSet();
                java.util.List<Object> delList = dialog.getDelList();
                if (delList.size() != 0) {
                    for (Object obj : delList) {
                        if (obj instanceof IProject) {
                            IProject p = (IProject) obj;
                            if (projectsMap.containsKey(p.getName())) {
                                projectsMap.remove(p.getName());
                                String name = convertorMapper.get(p.getName());
                                if (name != null) {
                                    convertorMapper.remove(p.getName());
                                    TOSLoginComposite.this.projectListViewer.getList().remove(name);
                                }
                                if (TOSLoginComposite.this.projectListViewer.getList().getItemCount() == 0) {
                                    enableOpenAndDelete(false);
                                } else if (TOSLoginComposite.this.projectListViewer.getSelection().isEmpty()) {
                                    TOSLoginComposite.this.projectListViewer.getList().select(0);
                                }
                                try {
                                    setStatusArea();
                                } catch (PersistenceException e1) {
                                    ExceptionHandler.process(e1);
                                }
                            }
                        }
                    }
                }
            }
            refresh();
        }
    });
    importButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ImportDemoProjectAction.getInstance().setShell(getShell());
            ImportProjectAsAction.getInstance().run();
            String newProject = ImportProjectAsAction.getInstance().getProjectName();
            if (newProject != null) {
                ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
                Project[] projects = null;
                try {
                    projects = repositoryFactory.readProject();
                } catch (PersistenceException e1) {
                    e1.printStackTrace();
                } catch (BusinessException e1) {
                    e1.printStackTrace();
                }
                if (!projectsMap.containsKey(newProject.toUpperCase())) {
                    for (Project project : projects) {
                        if (project.getLabel().toUpperCase().equals(newProject.toUpperCase())) {
                            projectsMap.put(newProject.toUpperCase(), project);
                            convertorMapper.put(newProject.toUpperCase(), newProject);
                            enableOpenAndDelete(true);
                            try {
                                setStatusArea();
                            } catch (PersistenceException e1) {
                                ExceptionHandler.process(e1);
                            }
                        }
                    }
                    TOSLoginComposite.this.projectListViewer.setInput(new ArrayList(convertorMapper.values()));
                }
            }
            try {
                IRunnableWithProgress op = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            ProxyRepositoryFactory.getInstance().initialize();
                        } catch (PersistenceException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                };
                new ProgressMonitorDialog(getShell()).run(true, false, op);
                refresh();
            } catch (InvocationTargetException e1) {
                e1.getTargetException();
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    });
    changeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dirDialog = new DirectoryDialog(dialog.getShell());
            String path = dirDialog.open();
            if (path == null || "".equals(path)) {
                //$NON-NLS-1$
                workspaceText.setText(getRecentWorkSpace());
                loginComposite.getConnection().setWorkSpace(getRecentWorkSpace());
            } else {
                workspaceText.setText(path);
                loginComposite.getConnection().setWorkSpace(path);
                if (!path.equals(oldPath)) {
                    oldPath = path;
                    restartBut.setVisible(true);
                    openButton.setEnabled(false);
                    deleteButton.setEnabled(false);
                    createButton.setEnabled(false);
                    importButton.setEnabled(false);
                    demoProjectButton.setEnabled(false);
                    changeButton.setEnabled(false);
                }
            }
            java.util.List<ConnectionBean> list = new ArrayList<ConnectionBean>();
            list.add(loginComposite.getConnection());
            loginComposite.storedConnections = list;
            perReader.saveConnections(loginComposite.storedConnections);
            if (!loginComposite.isWorkSpaceSame()) {
                try {
                    setStatusArea();
                } catch (PersistenceException e1) {
                    ExceptionHandler.process(e1);
                }
            }
        }
    });
    restartBut.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            LoginComposite.isRestart = true;
            ConnectionBean connection = loginComposite.getConnection();
            perReader.saveLastConnectionBean(connection);
            // update the restart command line to specify the workspace to launch
            // if relaunch, should delete the "disableLoginDialog" argument in eclipse data for bug TDI-19214
            //$NON-NLS-1$
            EclipseCommandLine.updateOrCreateExitDataPropertyWithCommand("-data", connection.getWorkSpace(), false);
            // store the workspace in the eclipse history so that it is rememebered on next studio launch
            //$NON-NLS-1$
            ChooseWorkspaceData workspaceData = new ChooseWorkspaceData("");
            workspaceData.workspaceSelected(connection.getWorkSpace());
            workspaceData.writePersistedData();
            dialog.okPressed();
        }
    });
    openButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            loginComposite.setRepositoryContextInContext();
            if (!TOSLoginComposite.this.projectListViewer.getSelection().isEmpty()) {
                String selection = TOSLoginComposite.this.projectListViewer.getList().getSelection()[0];
                if (selection != null && !selection.equals("")) {
                    Project project = (Project) projectsMap.get(selection.toUpperCase());
                    boolean flag = dialog.logIn(project);
                    if (flag) {
                        dialog.okPressed();
                    }
                }
            }
        }
    });
    demoProjectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ImportDemoProjectAction action = ImportDemoProjectAction.getInstance();
            action.setShell(getShell());
            action.run();
            refresh();
        }
    });
}
Also used : ImportDemoProjectAction(org.talend.repository.ui.actions.importproject.ImportDemoProjectAction) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) BusinessException(org.talend.commons.exception.BusinessException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) NewProjectWizard(org.talend.repository.ui.wizards.newproject.NewProjectWizard) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) ChooseWorkspaceData(org.talend.core.ui.workspace.ChooseWorkspaceData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) SelectDeleteProjectDialog(org.talend.repository.ui.actions.importproject.SelectDeleteProjectDialog) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) ConnectionBean(org.talend.core.model.general.ConnectionBean) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 IProject (org.eclipse.core.resources.IProject)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 DirectoryDialog (org.eclipse.swt.widgets.DirectoryDialog)1 Shell (org.eclipse.swt.widgets.Shell)1 BusinessException (org.talend.commons.exception.BusinessException)1 PersistenceException (org.talend.commons.exception.PersistenceException)1 ConnectionBean (org.talend.core.model.general.ConnectionBean)1 Project (org.talend.core.model.general.Project)1 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)1 ChooseWorkspaceData (org.talend.core.ui.workspace.ChooseWorkspaceData)1 ImportDemoProjectAction (org.talend.repository.ui.actions.importproject.ImportDemoProjectAction)1 SelectDeleteProjectDialog (org.talend.repository.ui.actions.importproject.SelectDeleteProjectDialog)1 NewProjectWizard (org.talend.repository.ui.wizards.newproject.NewProjectWizard)1