Search in sources :

Example 51 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class RepositoryService method isloginDialogDisabled.

private boolean isloginDialogDisabled() {
    //$NON-NLS-1$
    boolean reload = Boolean.parseBoolean(System.getProperty("talend.project.reload"));
    PreferenceManipulator preferenceManipulator = new PreferenceManipulator();
    ConnectionBean lastBean = null;
    if (reload) {
        final ConnectionUserPerReader instance = ConnectionUserPerReader.getInstance();
        instance.forceReadConnections();
        final String lastConncetion = ConnectionUserPerReader.getInstance().readLastConncetion();
        for (ConnectionBean bean : instance.readConnections()) {
            if (bean.getName().equals(lastConncetion)) {
                lastBean = bean;
                break;
            }
        }
    }
    if (ArrayUtils.contains(Platform.getApplicationArgs(), EclipseCommandLine.TALEND_DISABLE_LOGINDIALOG_COMMAND)) {
        //$NON-NLS-1$
        boolean deleteProjectIfExist = ArrayUtils.contains(Platform.getApplicationArgs(), "--deleteProjectIfExist");
        IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
        brandingService.getBrandingConfiguration().setUseProductRegistration(false);
        ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
        //$NON-NLS-1$ //$NON-NLS-2$
        String projectName = getAppArgValue("-project", "AUTO_LOGIN_PROJECT");
        //$NON-NLS-1$
        String language = getAppArgValue("-language", ECodeLanguage.JAVA.getName());
        //$NON-NLS-1$ //$NON-NLS-2$
        String login = getAppArgValue("-login", "auto@login.com");
        //$NON-NLS-1$ //$NON-NLS-2$
        String password = getAppArgValue("-loginPass", "");
        //$NON-NLS-1$
        String tacURL = getAppArgValue("-tacURL", null);
        // if tacURL is null, the branch will be no useful.
        //$NON-NLS-1$
        String branch = getAppArgValue("-branch", null);
        // if tacURL is not null, will be remote
        final boolean isRemote = tacURL != null;
        if (reload && lastBean != null) {
            final String lastProject = preferenceManipulator.getLastProject();
            if (lastProject != null) {
                projectName = lastProject;
            }
            final String lastUser = lastBean.getUser();
            if (lastUser != null) {
                login = lastUser;
            }
            final String lastPass = lastBean.getPassword();
            if (lastPass != null) {
                password = lastPass;
            }
        }
        User userInfo = PropertiesFactoryImpl.eINSTANCE.createUser();
        userInfo.setLogin(login);
        try {
            userInfo.setPassword(PasswordHelper.encryptPasswd(password));
        } catch (NoSuchAlgorithmException e) {
            ExceptionHandler.process(e);
        }
        LoginHelper.isAutoLogonFailed = false;
        try {
            ConnectionBean bean = null;
            if (reload && lastBean != null) {
                // reload
                bean = lastBean;
            } else {
                if (tacURL != null && isRemote) {
                    // remote
                    bean = ConnectionBean.getDefaultRemoteConnectionBean();
                    bean.setUser(login);
                    bean.setPassword(password);
                    bean.getDynamicFields().put(RepositoryConstants.REPOSITORY_URL, tacURL);
                } else {
                    bean = ConnectionBean.getDefaultConnectionBean();
                }
            }
            Context ctx = CorePlugin.getContext();
            RepositoryContext repositoryContext = new RepositoryContext();
            ctx.putProperty(Context.REPOSITORY_CONTEXT_KEY, repositoryContext);
            repositoryContext.setUser(userInfo);
            repositoryContext.setClearPassword(password);
            repositoryContext.setFields(bean.getDynamicFields());
            repositoryFactory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(bean.getRepositoryId()));
            Project project = null;
            for (Project p : repositoryFactory.readProject()) {
                if (p.getLabel().equals(projectName) || p.getTechnicalLabel().equals(projectName)) {
                    project = p;
                    break;
                }
            }
            if (!reload) {
                if (deleteProjectIfExist && project != null) {
                    IWorkspace workspace = ResourcesPlugin.getWorkspace();
                    IProject eclipseProject = workspace.getRoot().getProject(project.getTechnicalLabel());
                    if (eclipseProject.exists()) {
                        eclipseProject.delete(true, new NullProgressMonitor());
                    }
                }
                if (!isRemote && (project == null || deleteProjectIfExist)) {
                    Project projectInfor = //$NON-NLS-1$
                    ProjectHelper.createProject(//$NON-NLS-1$
                    projectName, //$NON-NLS-1$
                    "", language, userInfo);
                    project = repositoryFactory.createProject(projectInfor);
                }
            } else {
                if (project != null && !project.getEmfProject().isLocal() && repositoryFactory.isLocalConnectionProvider()) {
                    List<IRepositoryFactory> rfList = RepositoryFactoryProvider.getAvailableRepositories();
                    IRepositoryFactory remoteFactory = null;
                    for (IRepositoryFactory rf : rfList) {
                        if (!rf.isLocalConnectionProvider()) {
                            remoteFactory = rf;
                            break;
                        }
                    }
                    if (remoteFactory != null) {
                        repositoryFactory.setRepositoryFactoryFromProvider(remoteFactory);
                        repositoryFactory.getRepositoryContext().setOffline(true);
                    }
                }
            }
            if (!repositoryFactory.isLocalConnectionProvider()) {
                ProjectManager.getInstance().setMainProjectBranch(project, preferenceManipulator.getLastSVNBranch(new JSONObject(project.getEmfProject().getUrl()).getString("location"), project.getTechnicalLabel()));
            }
            if (project != null && reload && lastBean != null && repositoryFactory.getRepositoryContext().isOffline()) {
                if (PluginChecker.isSVNProviderPluginLoaded()) {
                    ISVNProviderService svnProviderService = (ISVNProviderService) GlobalServiceRegister.getDefault().getService(ISVNProviderService.class);
                    if (svnProviderService.isSVNProject(project)) {
                        String projectUrl = svnProviderService.getProjectUrl(project);
                        String lastBranch = preferenceManipulator.getLastSVNBranch(projectUrl, project.getTechnicalLabel());
                        ProjectManager.getInstance().setMainProjectBranch(project, lastBranch);
                    }
                }
            }
            if (project == null) {
                //$NON-NLS-1$
                throw new LoginException(Messages.getString("RepositoryService.projectNotFound", projectName));
            }
            repositoryContext.setProject(project);
            repositoryFactory.logOnProject(project, new NullProgressMonitor());
        } catch (final PersistenceException e) {
            if (e instanceof OperationCancelException) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("LoginDialog.logonCanceled"), e.getLocalizedMessage());
                    }
                });
            } else {
                MessageBoxExceptionHandler.process(e, new Shell());
            }
            repositoryFactory.logOffProject();
            LoginHelper.isAutoLogonFailed = true;
        } catch (LoginException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            LoginHelper.isAutoLogonFailed = true;
        } catch (BusinessException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            LoginHelper.isAutoLogonFailed = true;
        } catch (CoreException e) {
            MessageBoxExceptionHandler.process(e, new Shell());
            repositoryFactory.logOffProject();
            LoginHelper.isAutoLogonFailed = true;
        } catch (JSONException e) {
            ExceptionHandler.process(e);
            LoginHelper.isAutoLogonFailed = true;
        }
        if (LoginHelper.isAutoLogonFailed) {
            LoginHelper.isRestart = true;
        }
        return true;
    }
    return false;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RepositoryContext(org.talend.core.context.RepositoryContext) PreferenceManipulator(org.talend.core.prefs.PreferenceManipulator) User(org.talend.core.model.properties.User) OperationCancelException(org.talend.commons.exception.OperationCancelException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Shell(org.eclipse.swt.widgets.Shell) BusinessException(org.talend.commons.exception.BusinessException) ConnectionUserPerReader(org.talend.repository.ui.login.connections.ConnectionUserPerReader) IContext(org.talend.core.model.process.IContext) RepositoryContext(org.talend.core.context.RepositoryContext) Context(org.talend.core.context.Context) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ISVNProviderService(org.talend.core.services.ISVNProviderService) JSONException(org.talend.utils.json.JSONException) IBrandingService(org.talend.core.ui.branding.IBrandingService) IProject(org.eclipse.core.resources.IProject) IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) JSONObject(org.talend.utils.json.JSONObject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) ConnectionBean(org.talend.core.model.general.ConnectionBean)

Example 52 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class CreateSandboxProjectDialog method addProjectListeners.

private void addProjectListeners() {
    ModifyListener listener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            if (e.widget == urlText.getTextControl()) {
                enableSandboxProject = false;
            }
            checkFields();
        }
    };
    urlText.addModifyListener(listener);
    projectLabelText.addModifyListener(listener);
    checkBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (urlText.getText().trim().length() > 0) {
                Context ctx = CorePlugin.getContext();
                RepositoryContext oldContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
                try {
                    ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                    // always remote
                    // if (factory.getRepositoryFactoryFromProvider() == null) { //
                    factory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(RepositoryConstants.REPOSITORY_REMOTE_ID));
                    // }
                    if (factory.isLocalConnectionProvider()) {
                        //$NON-NLS-1$ 
                        MessageDialog.openError(//$NON-NLS-1$ 
                        getShell(), //$NON-NLS-1$ 
                        Messages.getString("CreateSandboxProjectDialog.ErrorTitle"), //$NON-NLS-1$ 
                        Messages.getString("CreateSandboxProjectDialog.ErrorLocalSuppportMessages"));
                    } else {
                        // set url for
                        RepositoryContext repositoryContext = new RepositoryContext();
                        repositoryContext.setFields(new HashMap<String, String>());
                        repositoryContext.setClearPassword(originRepCtx.getClearPassword());
                        repositoryContext.setUser(originRepCtx.getUser());
                        repositoryContext.getFields().put(RepositoryConstants.REPOSITORY_URL, urlText.getText());
                        ctx.putProperty(Context.REPOSITORY_CONTEXT_KEY, repositoryContext);
                        //
                        enableSandboxProject = factory.enableSandboxProject();
                        if (!enableSandboxProject) {
                            //$NON-NLS-1$ 
                            MessageDialog.openError(//$NON-NLS-1$ 
                            getShell(), //$NON-NLS-1$ 
                            Messages.getString("CreateSandboxProjectDialog.ErrorTitle"), //$NON-NLS-1$ 
                            Messages.getString("CreateSandboxProjectDialog.ErrorSuppportMessages"));
                        }
                    }
                } catch (PersistenceException e1) {
                    ExceptionHandler.process(e1);
                    //$NON-NLS-1$ 
                    MessageDialog.openError(//$NON-NLS-1$ 
                    getShell(), //$NON-NLS-1$ 
                    Messages.getString("CreateSandboxProjectDialog.ErrorTitle"), e1.getMessage());
                } finally {
                    // revert
                    if (oldContext != null) {
                        ctx.putProperty(Context.REPOSITORY_CONTEXT_KEY, oldContext);
                    }
                }
            }
            checkFields();
        }
    });
}
Also used : Context(org.talend.core.context.Context) RepositoryContext(org.talend.core.context.RepositoryContext) ModifyEvent(org.eclipse.swt.events.ModifyEvent) RepositoryContext(org.talend.core.context.RepositoryContext) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ModifyListener(org.eclipse.swt.events.ModifyListener) HashMap(java.util.HashMap) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 53 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class CreateSandboxProjectDialog method okPressed.

@Override
protected void okPressed() {
    //        boolean confirm = MessageDialog.openConfirm(getShell(), Messages.getString("CreateSandboxProjectDialog.ConfirmTitle"), //$NON-NLS-1$
    //                Messages.getString("CreateSandboxProjectDialog.ConfirmMessages")); //$NON-NLS-1$ 
    // if (!confirm) {
    // super.okPressed();
    // return;
    // }
    //
    final String url = urlText.getText();
    final String projectName = projectLabelText.getText();
    final String projectLanguage = languageCombo.getText();
    final String projectAuthor = userLoginText.getText();
    final String projectAuthorPass = userPassText.getText();
    final String projectAuthorFirstname = userFirstNameText.getText();
    final String projectAuthorLastname = userLastNameText.getText();
    // final boolean needCreateNewConn = !existedBeforeConn() || !url.trim().equals(getExistedBeforeConnURL());
    bean = new ConnectionBean();
    bean.setRepositoryId(RepositoryConstants.REPOSITORY_REMOTE_ID);
    bean.setUser(projectAuthor);
    bean.setPassword(projectAuthorPass);
    bean.setName(generateConnectionName(projectAuthor));
    bean.setDescription(bean.getName());
    bean.setWorkSpace(new Path(Platform.getInstanceLocation().getURL().getPath()).toFile().getPath());
    bean.getDynamicFields().put(RepositoryConstants.REPOSITORY_URL, url);
    bean.setComplete(true);
    // set context for url and in order to create project later.
    RepositoryContext repositoryContext = new RepositoryContext();
    // if (existedBeforeConn()) {
    // Context ctx = CorePlugin.getContext();
    // RepositoryContext oldContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
    // repositoryContext.setUser(oldContext.getUser());
    // repositoryContext.setClearPassword(oldContext.getClearPassword());
    // } else {
    User user = ProjectHelper.createUser(projectAuthor, projectAuthorPass, projectAuthorFirstname, projectAuthorLastname, false);
    repositoryContext.setUser(user);
    repositoryContext.setClearPassword(projectAuthorPass);
    // }
    repositoryContext.setFields(bean.getDynamicFields());
    Context ctx = CorePlugin.getContext();
    ctx.putProperty(Context.REPOSITORY_CONTEXT_KEY, repositoryContext);
    // set provider
    // if (!existedBeforeConn()) { // no connection
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    repositoryFactory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(bean.getRepositoryId()));
    // }
    //
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            Display disp = Display.getCurrent();
            if (disp == null) {
                disp = Display.getDefault();
            }
            disp.syncExec(new Runnable() {

                @Override
                public void run() {
                    //$NON-NLS-1$
                    monitor.beginTask("Creating...", IProgressMonitor.UNKNOWN);
                    Project projectInfor = ProjectHelper.createProject(projectName, projectName, projectLanguage, projectAuthor, projectAuthorPass, projectAuthorFirstname, projectAuthorLastname, false);
                    projectInfor.setSandboxProject(true);
                    boolean ok = false;
                    try {
                        User authUser = originRepCtx.getUser();
                        String authPassword = originRepCtx.getClearPassword();
                        Project createProject = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().createProject(authUser, authPassword, projectInfor);
                        ok = (createProject != null);
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                        //$NON-NLS-1$
                        MessageDialog.openError(//$NON-NLS-1$
                        getShell(), //$NON-NLS-1$
                        Messages.getString("CreateSandboxProjectDialog.Failure"), //$NON-NLS-1$
                        Messages.getString("CreateSandboxProjectDialog.failureMessage") + "\n\n" + //$NON-NLS-1$
                        e.getMessage());
                    }
                    if (ok) {
                        // if not created, will don't close the dialog
                        //$NON-NLS-1$
                        String messages = Messages.getString("CreateSandboxProjectDialog.successMessage");
                        // if (needCreateNewConn) {
                        messages += //$NON-NLS-1$ 
                        "\n\n" + //$NON-NLS-1$
                        Messages.getString("CreateSandboxProjectDialog.creatingConnectionMessages", bean.getName());
                        // }
                        MessageDialog.openInformation(getShell(), Messages.getString("CreateSandboxProjectDialog.successTitile"), //$NON-NLS-1$
                        messages);
                        // if (needCreateNewConn) {
                        // save connection
                        ConnectionUserPerReader instance = ConnectionUserPerReader.getInstance();
                        List<ConnectionBean> connections = instance.forceReadConnections();
                        connections.add(bean);
                        instance.saveConnections(connections);
                        // }
                        CreateSandboxProjectDialog.super.okPressed();
                    }
                    monitor.done();
                }
            });
        }
    };
    try {
        // final ProgressMonitorJobsDialog dialog = new ProgressMonitorJobsDialog(getShell());
        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
        dialog.run(true, false, runnable);
    } catch (InvocationTargetException e) {
        ExceptionHandler.process(e);
    } catch (InterruptedException e) {
        ExceptionHandler.process(e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Context(org.talend.core.context.Context) RepositoryContext(org.talend.core.context.RepositoryContext) RepositoryContext(org.talend.core.context.RepositoryContext) User(org.talend.core.model.properties.User) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Project(org.talend.core.model.general.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) ConnectionUserPerReader(org.talend.repository.ui.login.connections.ConnectionUserPerReader) PersistenceException(org.talend.commons.exception.PersistenceException) ConnectionBean(org.talend.core.model.general.ConnectionBean) List(java.util.List) Display(org.eclipse.swt.widgets.Display)

Example 54 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory 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)

Example 55 with ProxyRepositoryFactory

use of org.talend.core.repository.model.ProxyRepositoryFactory in project tdi-studio-se by Talend.

the class TOSLoginComposite method refresh.

private void refresh() {
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    Project[] projects = null;
    try {
        projects = repositoryFactory.readProject();
    } catch (PersistenceException e1) {
        ExceptionHandler.process(e1);
    } catch (BusinessException e1) {
        ExceptionHandler.process(e1);
    }
    this.projectListViewer.getList().removeAll();
    projectsMap.clear();
    convertorMapper.clear();
    if (projects != null) {
        for (Project pro : projects) {
            convertorMapper.put(pro.getTechnicalLabel(), pro.getLabel());
            projectsMap.put(pro.getTechnicalLabel(), pro);
            enableOpenAndDelete(true);
        }
        this.projectListViewer.setInput(new ArrayList(convertorMapper.values()));
    }
    try {
        setStatusArea();
    } catch (PersistenceException e1) {
        ExceptionHandler.process(e1);
    }
}
Also used : Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) BusinessException(org.talend.commons.exception.BusinessException) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) ArrayList(java.util.ArrayList)

Aggregations

ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)74 PersistenceException (org.talend.commons.exception.PersistenceException)32 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)25 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)22 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)18 EList (org.eclipse.emf.common.util.EList)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)11 Project (org.talend.core.model.general.Project)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 BusinessException (org.talend.commons.exception.BusinessException)8 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)8 ArrayList (java.util.ArrayList)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 Path (org.eclipse.core.runtime.Path)6 EConnectionType (org.talend.core.model.process.EConnectionType)6 ConnectionItem (org.talend.core.model.properties.ConnectionItem)6 List (java.util.List)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)5