Search in sources :

Example 16 with Context

use of org.talend.core.context.Context 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 17 with Context

use of org.talend.core.context.Context in project tdi-studio-se by Talend.

the class LoginProjectPage method createNewProject.

protected void createNewProject() {
    IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    Context ctx = CorePlugin.getContext();
    RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
    try {
        Project projectInfor = //$NON-NLS-1$
        ProjectHelper.createProject(//$NON-NLS-1$
        newProjectName.getText().trim().replace(' ', '_'), //$NON-NLS-1$
        "", ECodeLanguage.JAVA.getName(), repositoryContext.getUser());
        Project project = repositoryFactory.createProject(projectInfor);
        resetProjectOperationSelectionWithBusyCursor(false);
        fillUIProjectListWithBusyCursor();
        selectProject(project.getLabel());
        checkErrors();
        //$NON-NLS-1$
        newProjectName.setText("");
    } catch (PersistenceException e) {
        MessageDialog.openError(getShell(), Messages.getString("NewProjectWizard.failureTitle"), //$NON-NLS-1$
        Messages.getString(//$NON-NLS-1$ 
        "NewProjectWizard.failureText"));
        MessageBoxExceptionHandler.process(e);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        ExceptionHandler.process(e);
    }
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) Context(org.talend.core.context.Context) Project(org.talend.core.model.general.Project) RepositoryContext(org.talend.core.context.RepositoryContext) PersistenceException(org.talend.commons.exception.PersistenceException) JSONException(org.talend.utils.json.JSONException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 18 with Context

use of org.talend.core.context.Context in project tdi-studio-se by Talend.

the class DemosImportTest method initTempPro.

protected void initTempPro() throws PersistenceException, CoreException, LoginException {
    if (currentDemo == null) {
        // maybe license problem, the demo plugin is not loaded.
        return;
    }
    createTempDemoProject(demoName);
    Context ctx = CoreRuntimePlugin.getInstance().getContext();
    RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
    originalProject = repositoryContext.getProject();
    ProxyRepositoryFactory.getInstance().logOnProject(tempDemoProject, new NullProgressMonitor());
    // initilize the DQ sturcture for the original default project
    initDQStructure();
    repositoryContext.setProject(tempDemoProject);
}
Also used : Context(org.talend.core.context.Context) RepositoryContext(org.talend.core.context.RepositoryContext) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) RepositoryContext(org.talend.core.context.RepositoryContext)

Example 19 with Context

use of org.talend.core.context.Context in project tdi-studio-se by Talend.

the class NewProjectWizard method performFinish.

/**
     * @see org.eclipse.jface.wizard.Wizard#performFinish()
     */
@Override
public boolean performFinish() {
    IProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    Context ctx = CorePlugin.getContext();
    RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
    try {
        Project projectInfor = ProjectHelper.createProject(mainPage.getName().trim().replace(' ', '_'), mainPage.getDescription(), mainPage.getLanguage(), repositoryContext.getUser());
        project = repositoryFactory.createProject(projectInfor);
        return true;
    } catch (PersistenceException e) {
        MessageDialog.openError(getShell(), Messages.getString("NewProjectWizard.failureTitle"), //$NON-NLS-1$
        Messages.getString(//$NON-NLS-1$ //$NON-NLS-2$
        "NewProjectWizard.failureText"));
        MessageBoxExceptionHandler.process(e);
        return false;
    }
}
Also used : Context(org.talend.core.context.Context) RepositoryContext(org.talend.core.context.RepositoryContext) Project(org.talend.core.model.general.Project) RepositoryContext(org.talend.core.context.RepositoryContext) PersistenceException(org.talend.commons.exception.PersistenceException) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

Context (org.talend.core.context.Context)19 RepositoryContext (org.talend.core.context.RepositoryContext)17 PersistenceException (org.talend.commons.exception.PersistenceException)8 Project (org.talend.core.model.general.Project)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6 BeforeClass (org.junit.BeforeClass)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 EList (org.eclipse.emf.common.util.EList)2 AfterClass (org.junit.AfterClass)2 ConnectionBean (org.talend.core.model.general.ConnectionBean)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2 User (org.talend.core.model.properties.User)2 ConnectionUserPerReader (org.talend.repository.ui.login.connections.ConnectionUserPerReader)2 JSONException (org.talend.utils.json.JSONException)2 FileNotFoundException (java.io.FileNotFoundException)1