Search in sources :

Example 6 with IDynamicDistributionsGroup

use of org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup in project tbd-studio-se by Talend.

the class DynamicDistributionPreferenceForm method refreshVersionList.

private void refreshVersionList(IDynamicMonitor monitor) {
    try {
        IStructuredSelection selection = (IStructuredSelection) distributionCombo.getSelection();
        if (selection != null) {
            String selectedObject = (String) selection.getFirstElement();
            if (selectedObject != null) {
                IDynamicDistributionsGroup dynDistriGroup = DynamicDistributionManager.getInstance().getDynamicDistributionGroup(selectedObject);
                if (dynDistriGroup == null) {
                    throw new Exception(// $NON-NLS-1$
                    Messages.getString(// $NON-NLS-1$
                    "DynamicDistributionPreferenceForm.exception.noDistributionGroupFound", dynDistriGroup));
                }
                List<IDynamicPlugin> dynamicPlugins = new LinkedList<>();
                List<IDynamicPlugin> allBuiltinDynamicPlugins = dynDistriGroup.getAllBuiltinDynamicPlugins(monitor);
                if (allBuiltinDynamicPlugins != null && !allBuiltinDynamicPlugins.isEmpty()) {
                    dynamicPlugins.addAll(allBuiltinDynamicPlugins);
                }
                List<IDynamicPlugin> allUsersDynamicPlugins = DynamicDistributionManager.getInstance().getAllUsersDynamicPlugins(monitor);
                if (allUsersDynamicPlugins != null && !allUsersDynamicPlugins.isEmpty()) {
                    List<IDynamicPlugin> tempDynamicPlugins = dynDistriGroup.filterDynamicPlugins(allUsersDynamicPlugins, monitor);
                    if (tempDynamicPlugins != null && !tempDynamicPlugins.isEmpty()) {
                        dynamicPlugins.addAll(tempDynamicPlugins);
                    }
                }
                Collections.sort(dynamicPlugins, Collections.reverseOrder(new DynamicPluginComparator()));
                versionCombo.setInput(dynamicPlugins);
                if (!dynamicPlugins.isEmpty()) {
                    versionCombo.setSelection(new StructuredSelection(dynamicPlugins.get(0)));
                }
            }
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) DynamicPluginComparator(org.talend.hadoop.distribution.dynamic.comparator.DynamicPluginComparator) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) LinkedList(java.util.LinkedList)

Example 7 with IDynamicDistributionsGroup

use of org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup in project tbd-studio-se by Talend.

the class DynamicDistributionPreferenceForm method doDelete.

private void doDelete(IDynamicPlugin dynamicPlugin) throws Throwable {
    final Throwable[] throwable = new Throwable[1];
    ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(getShell());
    progressDialog.run(true, false, new IRunnableWithProgress() {

        @Override
        public void run(IProgressMonitor pMonitor) throws InvocationTargetException, InterruptedException {
            ProxyRepositoryFactory.getInstance().executeRepositoryWorkUnit(new RepositoryWorkUnit<Boolean>(// $NON-NLS-1$
            Messages.getString("DynamicDistributionPreferenceForm.form.deleteExistingConfig.workunit.title")) {

                @Override
                protected void run() throws LoginException, PersistenceException {
                    IDynamicMonitor monitor = new AbsDynamicProgressMonitor(pMonitor) {

                        @Override
                        public void writeMessage(String message) {
                        // nothing to do
                        }
                    };
                    try {
                        IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
                        monitor.beginTask(// $NON-NLS-1$
                        Messages.getString(// $NON-NLS-1$
                        "DynamicDistributionPreferenceForm.delete.progress.unregist", pluginConfiguration.getName()), IDynamicMonitor.UNKNOWN);
                        String distribution = pluginConfiguration.getDistribution();
                        IDynamicDistributionsGroup dynamicDistributionGroup = DynamicDistributionManager.getInstance().getDynamicDistributionGroup(distribution);
                        dynamicDistributionGroup.unregister(dynamicPlugin, monitor, false);
                        monitor.setTaskName(// $NON-NLS-1$
                        Messages.getString(// $NON-NLS-1$
                        "DynamicDistributionPreferenceForm.delete.progress.deleteFile", pluginConfiguration.getName()));
                        String filePath = (String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_FILE_PATH);
                        File file = new File(filePath);
                        file.delete();
                        monitor.setTaskName(// $NON-NLS-1$
                        Messages.getString("DynamicDistributionPreferenceForm.delete.progress.resetCache"));
                        DynamicDistributionManager.getInstance().resetSystemCache();
                    } catch (Throwable e) {
                        throwable[0] = e;
                    }
                }
            });
        }
    });
    if (throwable[0] != null) {
        throw throwable[0];
    }
}
Also used : ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) RepositoryWorkUnit(org.talend.repository.RepositoryWorkUnit) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) File(java.io.File) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) AbsDynamicProgressMonitor(org.talend.designer.maven.aether.AbsDynamicProgressMonitor)

Example 8 with IDynamicDistributionsGroup

use of org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup in project tbd-studio-se by Talend.

the class DynamicDistributionPreferenceForm method addListeners.

private void addListeners() {
    if (ITalendCorePrefConstants.DYNAMIC_DISTRIBUTION_SETTING == showPart) {
        distributionCombo.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                refreshVersionList(new DummyDynamicMonitor());
                updateButtons();
            }
        });
        versionCombo.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                updateButtons();
            }
        });
        buildConfigBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                try {
                    IStructuredSelection selection = (IStructuredSelection) distributionCombo.getSelection();
                    if (selection == null) {
                        ExceptionHandler.process(new Exception(// $NON-NLS-1$
                        Messages.getString("DynamicDistributionPreferenceForm.exception.noDistributionSelected")));
                        return;
                    }
                    String distribution = (String) selection.getFirstElement();
                    if (distribution == null) {
                        ExceptionHandler.process(new Exception(// $NON-NLS-1$
                        Messages.getString("DynamicDistributionPreferenceForm.exception.noDistributionSelected")));
                        return;
                    }
                    IDynamicDistributionsGroup dynamicDistributionsGroup = DynamicDistributionManager.getInstance().getDynamicDistributionGroup(distribution);
                    DynamicDistributionSetupData configData = new DynamicDistributionSetupData();
                    configData.setDynamicDistributionsGroup(dynamicDistributionsGroup);
                    DynamicDistributionSetupWizard wizard = new DynamicDistributionSetupWizard(configData);
                    WizardDialog wizardDialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
                    wizardDialog.setMinimumPageSize(600, 400);
                    wizardDialog.create();
                    if (wizardDialog.open() == IDialogConstants.OK_ID) {
                    // nothing to do
                    }
                    IDynamicMonitor monitor = new DummyDynamicMonitor();
                    refreshVersionList(monitor);
                } catch (Throwable ex) {
                    ExceptionHandler.process(ex);
                }
                updateButtons();
            }
        });
        deleteBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                onDeleteBtnPressed();
                updateButtons();
            }
        });
    } else {
        setupDistriCombo.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                try {
                    loadRepositorySetupGroup();
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                }
                updateButtons();
            }
        });
        overrideDefaultSetupBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                updateButtons();
            }
        });
        repositoryText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                String newRepositoryText = repositoryText.getText();
                if (StringUtils.equals(newRepositoryText, repositoryUrlCache)) {
                    return;
                }
                repositoryUrlCache = newRepositoryText;
                updateButtons();
            }
        });
        anonymousBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                updateButtons();
            }
        });
        userText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                String newUsername = userText.getText();
                if (StringUtils.equals(newUsername, usernameCache)) {
                    return;
                }
                usernameCache = newUsername;
                updateButtons();
            }
        });
        passwordText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                String newPassword = passwordText.getText();
                if (StringUtils.equals(newPassword, passwordCache)) {
                    return;
                }
                passwordCache = newPassword;
                updateButtons();
            }
        });
        checkConnectionBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (!isComplete()) {
                    return;
                }
                TypedReturnCode tc = new TypedReturnCode();
                try {
                    IDynamicDistributionsGroup distriGroup = getSelectedSetupDynamicDistriGroup();
                    DynamicConfiguration dynamicConfiguration = new DynamicConfiguration();
                    dynamicConfiguration.setDistribution(distriGroup.getDistribution());
                    IDependencyResolver dependencyResolver = distriGroup.getDependencyResolver(dynamicConfiguration);
                    tc = dependencyResolver.checkConnection(repositoryText.getText(), userText.getText(), passwordText.getText());
                } catch (Exception e1) {
                    ExceptionHandler.process(e1);
                    tc.setOk(false);
                    tc.setMessage(e1.getMessage());
                }
                showCheckConnectionInformation(true, tc);
            }
        });
    }
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IDependencyResolver(org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver) DynamicDistributionSetupWizard(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupWizard) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor)

Example 9 with IDynamicDistributionsGroup

use of org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup in project tbd-studio-se by Talend.

the class DynamicDistributionOptionForm method initData.

private void initData(IDynamicMonitor monitor) {
    try {
        namePluginMap = getNamePluginMap();
        getDynamicDistributionSetupData().setNamePluginMap(namePluginMap);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    DynamicDistributionSetupData dynConfigData = getDynamicDistributionSetupData();
    IDynamicDistributionsGroup dynamicDistributionsGroup = dynConfigData.getDynamicDistributionsGroup();
    dynamicConfiguration = new DynamicConfiguration();
    dynamicConfiguration.setDistribution(dynamicDistributionsGroup.getDistribution());
    try {
        refreshExistingConfigsCombo(monitor, dynamicDistributionsGroup);
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
}
Also used : IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with IDynamicDistributionsGroup

use of org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup in project tbd-studio-se by Talend.

the class DynamicDistributionPreferenceForm method performDefaults.

@Override
public boolean performDefaults() {
    boolean isReadonly = isReadonly();
    if (isReadonly) {
        super.performDefaults();
        return false;
    }
    boolean agree = MessageDialog.openConfirm(getShell(), // $NON-NLS-1$
    Messages.getString("DynamicDistributionPreferenceForm.performDefaults.confirm.title"), // $NON-NLS-1$
    Messages.getString("DynamicDistributionPreferenceForm.performDefaults.confirm.message"));
    if (!agree) {
        return false;
    }
    try {
        IDynamicDistributionsGroup selectedSetupDynamicDistriGroup = getSelectedSetupDynamicDistriGroup();
        if (selectedSetupDynamicDistriGroup != null) {
            IDynamicDistributionPreference dynamicDistributionPreference = selectedSetupDynamicDistriGroup.getDynamicDistributionPreference(ProjectManager.getInstance().getCurrentProject());
            if (dynamicDistributionPreference != null) {
                boolean changed = false;
                boolean isAnonymous = dynamicDistributionPreference.getDefaultIsAnonymous();
                changed = changed || dynamicDistributionPreference.isAnonymous() != isAnonymous;
                dynamicDistributionPreference.setAnonymous(isAnonymous);
                boolean overrideDefaultSetup = dynamicDistributionPreference.getDefaultOverrideDefaultSetup();
                changed = changed || dynamicDistributionPreference.overrideDefaultSetup() != overrideDefaultSetup;
                dynamicDistributionPreference.setOverrideDefaultSetup(overrideDefaultSetup);
                String password = dynamicDistributionPreference.getDefaultPassword();
                changed = changed || !StringUtils.equals(dynamicDistributionPreference.getPassword(), password);
                dynamicDistributionPreference.setPassword(password);
                String repository = dynamicDistributionPreference.getDefaultRepository();
                changed = changed || !StringUtils.equals(dynamicDistributionPreference.getRepository(), repository);
                dynamicDistributionPreference.setRepository(repository);
                String username = dynamicDistributionPreference.getDefaultUsername();
                changed = changed || !StringUtils.equals(dynamicDistributionPreference.getUsername(), username);
                dynamicDistributionPreference.setUsername(username);
                dynamicDistributionPreference.save();
                loadRepositorySetupGroup();
                isComplete();
                if (changed) {
                    reloadDynamicDistributions();
                }
            }
        }
    } catch (Throwable e) {
        ExceptionHandler.process(e);
        String message = e.getMessage();
        if (StringUtils.isEmpty(message)) {
            // $NON-NLS-1$
            message = Messages.getString("ExceptionDialog.message.empty");
        }
        // $NON-NLS-1$
        ExceptionMessageDialog.openError(getShell(), Messages.getString("ExceptionDialog.title"), message, e);
    }
    return super.performDefaults();
}
Also used : IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup)

Aggregations

IDynamicDistributionsGroup (org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup)13 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 DynamicDistributionSetupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData)6 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 LoginException (org.talend.commons.exception.LoginException)4 PersistenceException (org.talend.commons.exception.PersistenceException)4 IDynamicMonitor (org.talend.designer.maven.aether.IDynamicMonitor)4 IDynamicDistributionPreference (org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference)4 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 IDynamicPlugin (org.talend.core.runtime.dynamic.IDynamicPlugin)3 AbsDynamicProgressMonitor (org.talend.designer.maven.aether.AbsDynamicProgressMonitor)3 List (java.util.List)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)2 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)2 File (java.io.File)1 Calendar (java.util.Calendar)1