Search in sources :

Example 1 with IExchangeService

use of org.talend.core.service.IExchangeService in project tdi-studio-se by Talend.

the class ExchangeLoginTask method run.

/* (non-Javadoc)
     * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
     */
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    if (!PluginChecker.isExchangeSystemLoaded() || TalendPropertiesUtil.isHideExchange()) {
        return;
    }
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    "Check Exchange") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            // check for Talendforge
            IPreferenceStore prefStore = PlatformUI.getPreferenceStore();
            boolean checkTisVersion = prefStore.getBoolean(ITalendCorePrefConstants.EXCHANGE_CHECK_TIS_VERSION);
            IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
            if (!checkTisVersion && brandingService.isPoweredbyTalend()) {
                int count = prefStore.getInt(TalendForgeDialog.LOGINCOUNT);
                if (count < 0) {
                    count = 1;
                }
                ExchangeUser exchangeUser = ProjectManager.getInstance().getCurrentProject().getExchangeUser();
                //$NON-NLS-1$
                boolean isExchangeLogon = exchangeUser.getLogin() != null && !exchangeUser.getLogin().equals("");
                boolean isUserPassRight = true;
                if (isExchangeLogon) {
                    IExchangeService service = (IExchangeService) GlobalServiceRegister.getDefault().getService(IExchangeService.class);
                    if (service.checkUserAndPass(exchangeUser.getUsername(), exchangeUser.getPassword()) != null) {
                        isUserPassRight = false;
                    }
                }
                if (!isExchangeLogon || !isUserPassRight) {
                    if ((count + 1) % 4 == 0) {
                        // if (Platform.getOS().equals(Platform.OS_LINUX)) {
                        // TalendForgeDialog tfDialog = new TalendForgeDialog(this.getShell(), project);
                        // tfDialog.open();
                        // } else {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                Project project = ProjectManager.getInstance().getCurrentProject();
                                String userEmail = null;
                                if (project.getAuthor() != null) {
                                    userEmail = project.getAuthor().getLogin();
                                }
                                TalendForgeDialog tfDialog = new TalendForgeDialog(DisplayUtils.getDefaultShell(), userEmail);
                                tfDialog.setBlockOnOpen(true);
                                tfDialog.open();
                            }
                        });
                    }
                    prefStore.setValue(TalendForgeDialog.LOGINCOUNT, count + 1);
                }
            }
            return org.eclipse.core.runtime.Status.OK_STATUS;
        }
    };
    job.setSystem(true);
    job.setUser(false);
    job.setPriority(Job.INTERACTIVE);
    // start as soon as possible
    job.schedule();
}
Also used : IBrandingService(org.talend.core.ui.branding.IBrandingService) ExchangeUser(org.talend.core.model.properties.ExchangeUser) Project(org.talend.core.model.general.Project) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IExchangeService(org.talend.core.service.IExchangeService) Job(org.eclipse.core.runtime.jobs.Job) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) TalendForgeDialog(org.talend.registration.wizards.register.TalendForgeDialog)

Example 2 with IExchangeService

use of org.talend.core.service.IExchangeService in project tdi-studio-se by Talend.

the class ImportItemWizardPage method createItemRoot.

private void createItemRoot(Composite workArea) {
    Composite projectGroup = new Composite(workArea, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 4;
    layout.makeColumnsEqualWidth = false;
    layout.marginWidth = 0;
    projectGroup.setLayout(layout);
    projectGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    itemFromDirectoryRadio = new Button(projectGroup, SWT.RADIO);
    // itemFromDirectoryRadio.setText(DataTransferMessages.WizardProjectsImportPage_RootSelectTitle);
    //$NON-NLS-1$
    itemFromDirectoryRadio.setText(Messages.getString("DataTransferMessages.WizardProjectsImportPage_RootSelectTitle"));
    this.directoryPathField = new Text(projectGroup, SWT.BORDER);
    this.directoryPathField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    browseDirectoriesButton = new Button(projectGroup, SWT.PUSH);
    // browseDirectoriesButton.setText(DataTransferMessages.DataTransfer_browse);
    //$NON-NLS-1$
    browseDirectoriesButton.setText(Messages.getString("DataTransferMessages.DataTransfer_browse"));
    setButtonLayoutData(browseDirectoriesButton);
    nothing = new Label(projectGroup, SWT.NONE);
    //$NON-NLS-1$
    nothing.setText(" ");
    // new project from archive radio button
    itemFromArchiveRadio = new Button(projectGroup, SWT.RADIO);
    // itemFromArchiveRadio.setText(DataTransferMessages.WizardProjectsImportPage_ArchiveSelectTitle);
    //$NON-NLS-1$
    itemFromArchiveRadio.setText(Messages.getString("DataTransferMessages.WizardProjectsImportPage_ArchiveSelectTitle"));
    // project location entry field
    archivePathField = new Text(projectGroup, SWT.BORDER);
    archivePathField.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    // browse button
    // Composite buttonCom = new Composite(projectGroup, SWT.NONE);
    // GridLayout buttonlayout = new GridLayout();
    // buttonlayout.numColumns = 2;
    // buttonlayout.makeColumnsEqualWidth = false;
    // buttonlayout.marginWidth = 0;
    // buttonCom.setLayout(buttonlayout);
    // buttonCom.setLayoutData(new GridData());
    browseArchivesButton = new Button(projectGroup, SWT.PUSH);
    // browseArchivesButton.setText(DataTransferMessages.DataTransfer_browse);
    //$NON-NLS-1$
    browseArchivesButton.setText(Messages.getString("DataTransferMessages.DataTransfer_browse"));
    setButtonLayoutData(browseArchivesButton);
    if (PluginChecker.isExchangeSystemLoaded() && !TalendPropertiesUtil.isHideExchange()) {
        selectExchangeButton = new Button(projectGroup, SWT.PUSH);
        //$NON-NLS-1$
        selectExchangeButton.setText(Messages.getString("ImportItemWizardPage.browseTalend"));
        setButtonLayoutData(selectExchangeButton);
        selectExchangeButton.setEnabled(false);
    }
    itemFromDirectoryRadio.setSelection(true);
    archivePathField.setEnabled(false);
    browseArchivesButton.setEnabled(false);
    browseDirectoriesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            handleLocationDirectoryButtonPressed();
        }
    });
    browseArchivesButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            handleLocationArchiveButtonPressed();
        }
    });
    if (selectExchangeButton != null) {
        selectExchangeButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                archivePathField.setEditable(false);
                IExchangeService service = (IExchangeService) GlobalServiceRegister.getDefault().getService(IExchangeService.class);
                selectedArchive = service.openExchangeDialog();
                if (selectedArchive != null) {
                    previouslyBrowsedArchive = selectedArchive;
                    archivePathField.setText(previouslyBrowsedArchive);
                    updateItemsList(selectedArchive, false);
                }
            }
        });
    }
    directoryPathField.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
                updateItemsList(directoryPathField.getText().trim(), false);
            }
        }
    });
    directoryPathField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
            updateItemsList(directoryPathField.getText().trim(), false);
        }
    });
    archivePathField.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent e) {
            if (e.detail == SWT.TRAVERSE_RETURN) {
                e.doit = false;
                updateItemsList(archivePathField.getText().trim(), false);
            }
        }
    });
    archivePathField.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(org.eclipse.swt.events.FocusEvent e) {
            updateItemsList(archivePathField.getText().trim(), false);
        }
    });
    itemFromDirectoryRadio.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            directoryRadioSelected();
        }
    });
    itemFromArchiveRadio.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            archiveRadioSelected();
        }
    });
}
Also used : FocusAdapter(org.eclipse.swt.events.FocusAdapter) TraverseEvent(org.eclipse.swt.events.TraverseEvent) Composite(org.eclipse.swt.widgets.Composite) TraverseListener(org.eclipse.swt.events.TraverseListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) GridLayout(org.eclipse.swt.layout.GridLayout) IExchangeService(org.talend.core.service.IExchangeService) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with IExchangeService

use of org.talend.core.service.IExchangeService in project tdi-studio-se by Talend.

the class LoginDialog method logIn.

/**
     * DOC smallet Comment method "logIn".
     * 
     * @param project
     * @throws Exception
     */
protected boolean logIn(final Project project) {
    final ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    ConnectionBean connBean = loginComposite.getConnection();
    final boolean needRestartForLocal = loginComposite.needRestartForLocal();
    if (connBean == null || project == null || project.getLabel() == null) {
        return false;
    }
    try {
        if (!project.getEmfProject().isLocal() && factory.isLocalConnectionProvider()) {
            List<IRepositoryFactory> rfList = RepositoryFactoryProvider.getAvailableRepositories();
            IRepositoryFactory remoteFactory = null;
            for (IRepositoryFactory rf : rfList) {
                if (!rf.isLocalConnectionProvider()) {
                    remoteFactory = rf;
                    break;
                }
            }
            if (remoteFactory != null) {
                factory.setRepositoryFactoryFromProvider(remoteFactory);
                factory.getRepositoryContext().setOffline(true);
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    // Save last used parameters
    PreferenceManipulator prefManipulator = new PreferenceManipulator(CorePlugin.getDefault().getPreferenceStore());
    prefManipulator.setLastProject(project.getTechnicalLabel());
    saveLastConnBean(connBean);
    // check for Talendforge
    if (PluginChecker.isExchangeSystemLoaded() && !TalendPropertiesUtil.isHideExchange()) {
        IPreferenceStore prefStore = PlatformUI.getPreferenceStore();
        boolean checkTisVersion = prefStore.getBoolean(ITalendCorePrefConstants.EXCHANGE_CHECK_TIS_VERSION);
        IBrandingService brandingService = (IBrandingService) GlobalServiceRegister.getDefault().getService(IBrandingService.class);
        if (!checkTisVersion && brandingService.isPoweredbyTalend()) {
            int count = prefStore.getInt(TalendForgeDialog.LOGINCOUNT);
            if (count < 0) {
                count = 1;
            }
            ExchangeUser exchangeUser = project.getExchangeUser();
            boolean isExchangeLogon = exchangeUser.getLogin() != null && !exchangeUser.getLogin().equals("");
            boolean isUserPassRight = true;
            if (isExchangeLogon) {
                IExchangeService service = (IExchangeService) GlobalServiceRegister.getDefault().getService(IExchangeService.class);
                if (service.checkUserAndPass(exchangeUser.getUsername(), exchangeUser.getPassword()) != null) {
                    isUserPassRight = false;
                }
            }
            if (!isExchangeLogon || !isUserPassRight) {
                if ((count + 1) % 4 == 0) {
                    // if (Platform.getOS().equals(Platform.OS_LINUX)) {
                    // TalendForgeDialog tfDialog = new TalendForgeDialog(this.getShell(), project);
                    // tfDialog.open();
                    // } else {
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            String userEmail = null;
                            if (project.getAuthor() != null) {
                                userEmail = project.getAuthor().getLogin();
                            }
                            TalendForgeDialog tfDialog = new TalendForgeDialog(getShell(), userEmail);
                            tfDialog.setBlockOnOpen(true);
                            tfDialog.open();
                        }
                    });
                }
                prefStore.setValue(TalendForgeDialog.LOGINCOUNT, count + 1);
            }
        }
    }
    try {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ICoreTisService.class)) {
            final ICoreTisService service = (ICoreTisService) GlobalServiceRegister.getDefault().getService(ICoreTisService.class);
            if (service != null) {
                // if in TIS then update the bundle status according to the project type
                if (!service.validProject(project, needRestartForLocal)) {
                    LoginComposite.isRestart = true;
                    return true;
                }
            }
        // else not in TIS so ignor caus we may not have a licence so we do not know which bundles belong to
        // DI, DQ or MDM
        }
    } catch (PersistenceException e) {
        e.printStackTrace();
        loginComposite.populateProjectList();
        MessageDialog.openError(getShell(), getShell().getText(), e.getMessage());
        return false;
    }
    final Shell shell = this.getShell();
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
    IRunnableWithProgress runnable = new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            // monitorWrap = new EventLoopProgressMonitor(monitor);
            try {
                factory.logOnProject(project, monitor);
            } catch (LoginException e) {
                throw new InvocationTargetException(e);
            } catch (PersistenceException e) {
                throw new InvocationTargetException(e);
            } catch (OperationCanceledException e) {
                throw new InterruptedException(e.getLocalizedMessage());
            }
            monitor.done();
        }
    };
    try {
        dialog.run(true, true, runnable);
    } catch (final InvocationTargetException e) {
        if (PluginChecker.isSVNProviderPluginLoaded()) {
            loginComposite.populateProjectList();
            if (e.getTargetException() instanceof OperationCancelException) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialog.openError(Display.getDefault().getActiveShell(), Messages.getString("LoginDialog.logonCanceled"), e.getTargetException().getLocalizedMessage());
                    }
                });
            } else {
                MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
            }
        } else {
            loginComposite.populateTOSProjectList();
            MessageBoxExceptionHandler.process(e.getTargetException(), getShell());
        }
        return false;
    } catch (InterruptedException e) {
        if (PluginChecker.isSVNProviderPluginLoaded()) {
            loginComposite.populateProjectList();
        } else {
            loginComposite.populateTOSProjectList();
        }
        return false;
    }
    return true;
}
Also used : PreferenceManipulator(org.talend.core.prefs.PreferenceManipulator) OperationCancelException(org.talend.commons.exception.OperationCancelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ICoreTisService(org.talend.core.services.ICoreTisService) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IExchangeService(org.talend.core.service.IExchangeService) Shell(org.eclipse.swt.widgets.Shell) IRepositoryFactory(org.talend.core.repository.model.IRepositoryFactory) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IBrandingService(org.talend.core.ui.branding.IBrandingService) ExchangeUser(org.talend.core.model.properties.ExchangeUser) Point(org.eclipse.swt.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) LoginException(org.talend.commons.exception.LoginException) ConnectionBean(org.talend.core.model.general.ConnectionBean) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) TalendForgeDialog(org.talend.registration.wizards.register.TalendForgeDialog)

Aggregations

IExchangeService (org.talend.core.service.IExchangeService)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 ExchangeUser (org.talend.core.model.properties.ExchangeUser)2 IBrandingService (org.talend.core.ui.branding.IBrandingService)2 TalendForgeDialog (org.talend.registration.wizards.register.TalendForgeDialog)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Job (org.eclipse.core.runtime.jobs.Job)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 FocusAdapter (org.eclipse.swt.events.FocusAdapter)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1