Search in sources :

Example 26 with RepositoryContext

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

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

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

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

the class TabFolderEditors method createStyledText.

private StyledText createStyledText(CTabItem item) {
    StyledText styledText = null;
    RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
    ECodeLanguage language = repositoryContext.getProject().getLanguage();
    IPreferenceStore preferenceStore = CorePlugin.getDefault().getPreferenceStore();
    styledText = new UnnotifiableColorStyledText(tabFolderEditors, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL, preferenceStore, language.getName());
    styledText.setEnabled(false);
    item.setControl(styledText);
    return styledText;
}
Also used : RepositoryContext(org.talend.core.context.RepositoryContext) StyledText(org.eclipse.swt.custom.StyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) UnnotifiableColorStyledText(org.talend.commons.ui.swt.colorstyledtext.UnnotifiableColorStyledText) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 30 with RepositoryContext

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

the class ExpressionBuilderDialog method getExpressionStorePath.

/**
     * yzhang Comment method "getExpressionStorePath".
     * 
     * @return
     */
protected String getExpressionStorePath() {
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    RepositoryContext repositoryContext = (RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY);
    Project project = repositoryContext.getProject();
    IProject p = root.getProject(project.getTechnicalLabel());
    // put to the temp folder
    String projectPath = p.getLocation().toPortableString() + File.separator + RepositoryConstants.TEMP_DIRECTORY;
    String configurationPath = projectPath + File.separator + ExpressionPersistance.CONFIGURATION_FOLDER_NAME;
    configurationPath = getValidFolderPath(configurationPath, 1);
    File configurationFolder = new File(configurationPath);
    if (!configurationFolder.exists()) {
        configurationFolder.mkdir();
    }
    String expressionPath = configurationPath + File.separator + ExpressionPersistance.EXPRESSION_FOLDER_NAME;
    expressionPath = getValidFolderPath(expressionPath, 1);
    File expressionFolder = new File(expressionPath);
    if (!expressionFolder.exists()) {
        expressionFolder.mkdir();
    }
    String jobName = "";
    if (component != null) {
        jobName = component.getProcess().getName();
    } else {
        jobName = "tXMLMap";
    }
    expressionPath = expressionPath + File.separator + jobName + XmlUtil.FILE_XML_SUFFIX;
    return expressionPath;
}
Also used : IProject(org.eclipse.core.resources.IProject) Project(org.talend.core.model.general.Project) RepositoryContext(org.talend.core.context.RepositoryContext) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Aggregations

RepositoryContext (org.talend.core.context.RepositoryContext)31 Context (org.talend.core.context.Context)17 Project (org.talend.core.model.general.Project)12 PersistenceException (org.talend.commons.exception.PersistenceException)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)7 IProject (org.eclipse.core.resources.IProject)5 ECodeLanguage (org.talend.core.language.ECodeLanguage)5 File (java.io.File)3 CoreException (org.eclipse.core.runtime.CoreException)3 BeforeClass (org.junit.BeforeClass)3 ProcessItem (org.talend.core.model.properties.ProcessItem)3 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)3 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2