Search in sources :

Example 66 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class LoginDialog method createDialogArea.

/**
     * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
     */
@Override
protected Control createDialogArea(final Composite parent) {
    Composite container = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    container.setLayout(layout);
    // container.setBackground(new Color(null, 215, 215, 215));
    container.setBackground(new Color(null, 255, 255, 255));
    IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
    new ImageCanvas(container, brandingService.getLoginVImage());
    if (!perReader.isHaveUserPer()) {
        perReader.createPropertyFile();
    }
    base = new Composite(container, SWT.NONE);
    base.setLayoutData(new GridData(GridData.FILL_BOTH));
    stackLayout = new StackLayout();
    base.setLayout(stackLayout);
    if (!PluginChecker.isSVNProviderPluginLoaded()) {
        // tos
        loginComposite = new LoginComposite(base, SWT.NONE, this, tosLoginComposite, stackLayout);
        loginComposite.populateProjectList();
        tosLoginComposite = new TOSLoginComposite(base, SWT.NONE, loginComposite, this);
    } else {
        loginComposite = new LoginComposite(base, SWT.NONE, this, tosLoginComposite, stackLayout);
    }
    GridData data = new GridData(GridData.FILL_BOTH);
    // data.widthHint = INNER_LOGIN_COMPOSITE_WIDTH;
    // data.heightHint = DIALOG_HEIGHT;
    loginComposite.setLayoutData(data);
    stackLayout.topControl = loginComposite;
    base.layout();
    if (!PluginChecker.isSVNProviderPluginLoaded()) {
        Project[] projectList = readProject();
        if (projectList.length > 0) {
            advanced();
        }
    }
    return container;
}
Also used : Project(org.talend.core.model.general.Project) GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) GridData(org.eclipse.swt.layout.GridData) StackLayout(org.eclipse.swt.custom.StackLayout) IBrandingService(org.talend.core.ui.branding.IBrandingService)

Example 67 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class LoginDialog method advanced.

public void advanced() {
    stackLayout.topControl = tosLoginComposite;
    base.layout();
    Project[] projectCollection = tosLoginComposite.readProject();
    Map<String, String> convertorMapper = tosLoginComposite.getConvertorMapper();
    for (Project element : projectCollection) {
        tosLoginComposite.getProjectMap().put(element.getLabel().toUpperCase(), element);
        convertorMapper.put(element.getLabel().toUpperCase(), element.getLabel());
    }
    ListViewer projectListViewer = tosLoginComposite.getProjectListViewer();
    projectListViewer.setInput(new ArrayList(convertorMapper.values()));
    try {
        tosLoginComposite.setStatusArea();
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (projectListViewer.getList().getItemCount() > 0) {
        projectListViewer.getList().select(0);
        tosLoginComposite.enableOpenAndDelete(true);
    }
}
Also used : Project(org.talend.core.model.general.Project) ListViewer(org.eclipse.jface.viewers.ListViewer) ArrayList(java.util.ArrayList) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 68 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class LoginHelper method getProjects.

public Project[] getProjects(ConnectionBean connBean, ErrorManager errorManager) {
    if (connBean == null) {
        return null;
    }
    Project[] projects = null;
    if (connBean != null) {
        String user2 = connBean.getUser();
        String repositoryId2 = connBean.getRepositoryId();
        String workSpace = connBean.getWorkSpace();
        String name = connBean.getName();
        if (//$NON-NLS-1$ //$NON-NLS-2$
        user2 != null && !"".equals(user2) && repositoryId2 != null && !"".equals(repositoryId2) && workSpace != null && !"".equals(workSpace) && name != null && !"".equals(name)) {
            //$NON-NLS-1$ //$NON-NLS-2$
            boolean valid = false;
            if (isRemoteConnection(connBean)) {
                String url = connBean.getDynamicFields().get(RepositoryConstants.REPOSITORY_URL);
                //$NON-NLS-1$
                valid = url != null && !"".equals(url);
            } else {
                valid = Pattern.matches(RepositoryConstants.MAIL_PATTERN, user2);
            }
            connBean.setComplete(valid);
        }
    }
    ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
    repositoryFactory.setRepositoryFactoryFromProvider(RepositoryFactoryProvider.getRepositoriyById(connBean.getRepositoryId()));
    if (!connBean.isComplete()) {
        return projects;
    }
    boolean initialized = false;
    //$NON-NLS-1$
    final String newLine = ":\n";
    try {
        try {
            repositoryFactory.checkAvailability();
        } catch (WarningException e) {
            String warnings = e.getMessage();
            if (warnings != null && !warnings.equals(lastWarnings)) {
                lastWarnings = warnings;
                if (errorManager != null) {
                    errorManager.setWarnMessage(warnings);
                } else {
                    final Shell shell = new Shell(DisplayUtils.getDisplay(), SWT.ON_TOP | SWT.TOP);
                    //$NON-NLS-1$
                    MessageDialog.openWarning(shell, Messages.getString("LoginComposite.warningTitle"), warnings);
                }
            }
        }
        OverTimePopupDialogTask<Boolean> overTimePopupDialogTask = new OverTimePopupDialogTask<Boolean>() {

            @Override
            public Boolean run() throws Throwable {
                ProxyRepositoryFactory.getInstance().initialize();
                return null;
            }
        };
        overTimePopupDialogTask.setNeedWaitingProgressJob(false);
        overTimePopupDialogTask.runTask();
        initialized = true;
    } catch (Throwable e) {
        projects = new Project[0];
        if (errorManager != null) {
            //$NON-NLS-1$
            errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
        } else {
            final Shell shell = new Shell(DisplayUtils.getDisplay(), SWT.ON_TOP | SWT.TOP);
            //$NON-NLS-1$
            MessageDialog.openError(//$NON-NLS-1$
            shell, //$NON-NLS-1$
            Messages.getString("LoginComposite.warningTitle"), //$NON-NLS-1$
            Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
        }
    }
    if (initialized) {
        try {
            OverTimePopupDialogTask<Project[]> overTimePopupDialogTask = new OverTimePopupDialogTask<Project[]>() {

                @Override
                public Project[] run() throws Throwable {
                    return ProxyRepositoryFactory.getInstance().readProject();
                }
            };
            overTimePopupDialogTask.setNeedWaitingProgressJob(false);
            projects = overTimePopupDialogTask.runTask();
            Arrays.sort(projects, new Comparator<Project>() {

                @Override
                public int compare(Project p1, Project p2) {
                    return p1.getLabel().compareTo(p2.getLabel());
                }
            });
        } catch (PersistenceException e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        } catch (BusinessException e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        } catch (Throwable e) {
            projects = new Project[0];
            if (errorManager != null) {
                //$NON-NLS-1$
                errorManager.setErrMessage(Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            } else {
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                getUsableShell(), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorTitle"), //$NON-NLS-1$
                Messages.getString("LoginComposite.errorMessages1") + newLine + e.getMessage());
            }
        }
    }
    return projects;
}
Also used : WarningException(org.talend.commons.exception.WarningException) Project(org.talend.core.model.general.Project) Shell(org.eclipse.swt.widgets.Shell) BusinessException(org.talend.commons.exception.BusinessException) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) OverTimePopupDialogTask(org.talend.repository.ui.dialog.OverTimePopupDialogTask) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 69 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class LoginProjectPage method refreshLicenseIfNeeded.

/**
     * 
     * @return if false: user cancel login
     */
private boolean refreshLicenseIfNeeded() {
    ConnectionBean conn = loginHelper.getCurrentSelectedConnBean();
    Project proj = getProject();
    if (LoginHelper.isRemoteConnection(conn)) {
        String url = getAdminURL();
        String projLabel = proj.getLabel();
        String userId = conn.getUser();
        try {
            String key = loginHelper.getLicenseMapKey(url, projLabel, userId);
            String license = loginHelper.getLicense(key);
            if (license == null || license.isEmpty()) {
                Job fetchJob = fetchLicenseJobMap.get(proj);
                if (fetchJob == null || fetchJob.getResult() != null) {
                    // if result is not null, means fetchJob has already finished but no license fetched
                    fetchJob = fetchLicense(proj);
                }
                final Job fJob = fetchJob;
                if (fJob != null) {
                    final AtomicBoolean isInterupted = new AtomicBoolean(false);
                    ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
                    dialog.run(true, true, new IRunnableWithProgress() {

                        @Override
                        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                            monitor.setTaskName(fJob.getName());
                            while (true) {
                                if (monitor.isCanceled()) {
                                    /**
                                         * If network is slow, maybe just wait the fetch job finish, but still can click
                                         * the Refresh button to cancel all fetch jobs
                                         */
                                    // fJob.cancel();
                                    isInterupted.set(true);
                                    break;
                                }
                                IStatus result = fJob.getResult();
                                if (result != null) {
                                    break;
                                }
                                try {
                                    Thread.sleep(250);
                                } catch (Exception e) {
                                // nothing to do
                                }
                            }
                        }
                    });
                    if (isInterupted.get()) {
                        return false;
                    }
                }
                license = loginHelper.getLicense(key);
            }
            if (license == null || license.isEmpty()) {
                //$NON-NLS-1$
                throw new Exception(Messages.getString("LoginProjectPage.fetchLicense.error.failed"));
            }
        // will do save in CoreTisService if needed
        // ICoreTisService tisService = (ICoreTisService) GlobalServiceRegister.getDefault()
        // .getService(ICoreTisService.class);
        // File remoteLicense = tisService.getRemoteLicenseFile();
        // tisService.storeLicenseFile(remoteLicense, license);
        } catch (Exception e) {
            //$NON-NLS-1$
            ExceptionMessageDialog.openError(//$NON-NLS-1$
            getShell(), //$NON-NLS-1$
            Messages.getString("LoginProjectPage.fetchLicense.error.title"), Messages.getString("LoginProjectPage.fetchLicense.error.msg"), //$NON-NLS-1$
            e);
            return false;
        }
    }
    return true;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SystemException(org.talend.commons.exception.SystemException) JSONException(org.talend.utils.json.JSONException) PersistenceException(org.talend.commons.exception.PersistenceException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Project(org.talend.core.model.general.Project) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ConnectionBean(org.talend.core.model.general.ConnectionBean) Job(org.eclipse.core.runtime.jobs.Job)

Example 70 with Project

use of org.talend.core.model.general.Project in project tdi-studio-se by Talend.

the class LoginFirstTimeStartupActionPage method importExistingProject.

protected void importExistingProject() {
    ImportProjectAsAction.getInstance().run();
    if (ImportProjectAsAction.getInstance().isImportedSeveralProjects()) {
        try {
            gotoNextPage();
        } catch (Throwable e) {
            CommonExceptionHandler.process(e);
        }
        return;
    }
    String importedExistingProjectName = ImportProjectAsAction.getInstance().getProjectName();
    if (importedExistingProjectName == null || importedExistingProjectName.isEmpty()) {
        return;
    }
    Project selectedProject = loginHelper.getProjectByName(loginHelper.getProjects(defaultConnectionBean), importedExistingProjectName);
    openProject(selectedProject);
}
Also used : Project(org.talend.core.model.general.Project)

Aggregations

Project (org.talend.core.model.general.Project)94 PersistenceException (org.talend.commons.exception.PersistenceException)47 IProject (org.eclipse.core.resources.IProject)38 File (java.io.File)18 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)18 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)13 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 RepositoryContext (org.talend.core.context.RepositoryContext)12 Property (org.talend.core.model.properties.Property)12 CoreException (org.eclipse.core.runtime.CoreException)10 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)10 List (java.util.List)9 IFolder (org.eclipse.core.resources.IFolder)8 Path (org.eclipse.core.runtime.Path)8 SystemException (org.talend.commons.exception.SystemException)8 JSONException (org.talend.utils.json.JSONException)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 ConnectionBean (org.talend.core.model.general.ConnectionBean)7 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)7