Search in sources :

Example 6 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class AbstractDynamicDistribution method getCompatibleTemplate.

@Override
public TemplateBean getCompatibleTemplate(IDynamicMonitor monitor, String version) throws Exception {
    if (monitor == null) {
        monitor = new DummyDynamicMonitor();
    }
    VersionStringComparator versionStringComparator = new VersionStringComparator();
    // 1. try to get compatible bean
    if (templateBeanCompatibleVersionMap == null) {
        getCompatibleVersions(monitor);
    }
    Set<Entry<TemplateBean, List<String>>> entrySet = templateBeanCompatibleVersionMap.entrySet();
    TemplateBean bestTemplateBean = null;
    // choose the biggest distance, normally means compatible with higher versions
    int distance = -1;
    for (Entry<TemplateBean, List<String>> entry : entrySet) {
        List<String> list = entry.getValue();
        Collections.sort(list, versionStringComparator);
        int size = list.size();
        int index = list.indexOf(version);
        if (0 <= index) {
            int curDistance = size - index;
            if (distance < curDistance) {
                distance = curDistance;
                bestTemplateBean = entry.getKey();
            }
        }
    }
    // 2. try to get bean from all beans
    if (bestTemplateBean == null) {
        List<String> allVersions = getAllVersions(monitor);
        Collections.sort(allVersions, versionStringComparator);
        // choose the shorted distance, normally means compatible with higher versions
        distance = -1;
        for (Entry<TemplateBean, List<String>> entry : entrySet) {
            List<String> list = entry.getValue();
            Collections.sort(list, versionStringComparator);
            String topVersion = list.get(list.size() - 1);
            String baseVersion = list.get(0);
            int curDistance = -1;
            if (versionStringComparator.compare(version, baseVersion) < 0) {
                curDistance = allVersions.indexOf(baseVersion) - allVersions.indexOf(version);
            } else {
                curDistance = allVersions.indexOf(version) - allVersions.indexOf(topVersion);
            }
            if (distance < 0 || curDistance < distance) {
                distance = curDistance;
                bestTemplateBean = entry.getKey();
            }
        }
    }
    return bestTemplateBean;
}
Also used : Entry(java.util.Map.Entry) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) VersionStringComparator(org.talend.designer.maven.aether.comparator.VersionStringComparator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Example 7 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class HadoopUiService method createDynamicDistributionPrefForm.

/* (non-Javadoc)
     * @see org.talend.core.ui.services.IHadoopUiService#createDynamicDistributionPrefForm(org.eclipse.swt.widgets.Composite)
     */
@Override
public IPreferenceForm createDynamicDistributionPrefForm(Composite parent, PreferencePage prefPage) {
    IDynamicMonitor monitor = new DummyDynamicMonitor();
    DynamicDistributionPreferenceForm existingConfigForm = new DynamicDistributionPreferenceForm(parent, SWT.NONE, monitor, ITalendCorePrefConstants.ARTIFACT_PROXY_SETTING);
    AbstractDynamicDistributionForm.ICheckListener checkListener = new ICheckListener() {

        @Override
        public String getMessage() {
            return prefPage.getMessage();
        }

        @Override
        public void showMessage(String message, int level) {
            prefPage.setMessage(message, level);
        }

        @Override
        public void updateButtons() {
            boolean isValid = existingConfigForm.isComplete();
            prefPage.setValid(isValid);
        }

        @Override
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws Exception {
            // $NON-NLS-1$
            throw new Exception("Please implement it if needed");
        }
    };
    existingConfigForm.setCheckListener(checkListener);
    return new IPreferenceForm() {

        @Override
        public void setLayoutData(Object layoutData) {
            existingConfigForm.setLayoutData(layoutData);
        }

        @Override
        public boolean performApply() {
            return existingConfigForm.performApply();
        }

        @Override
        public boolean performDefaults() {
            return existingConfigForm.performDefaults();
        }

        @Override
        public boolean isComplete() {
            return existingConfigForm.isComplete();
        }
    };
}
Also used : ICheckListener(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm.ICheckListener) ICheckListener(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm.ICheckListener) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) AbstractDynamicDistributionForm(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm) DynamicDistributionPreferenceForm(org.talend.repository.hadoopcluster.ui.dynamic.form.DynamicDistributionPreferenceForm) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) IPreferenceForm(org.talend.core.ui.services.IPreferenceForm) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 8 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class DynamicDistributionDetailsPage method createControl.

@Override
public void createControl(Composite parent) {
    IDynamicMonitor monitor = new DummyDynamicMonitor();
    AbstractDynamicDistributionForm.ICheckListener checkListener = new ICheckListener() {

        @Override
        public void showMessage(String message, int level) {
            setMessage(message, level);
            setErrorMessage(message);
        }

        @Override
        public void updateButtons() {
            getContainer().updateButtons();
        }

        @Override
        public String getMessage() {
            return DynamicDistributionDetailsPage.this.getMessage();
        }

        @Override
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws Exception {
            getContainer().run(fork, cancelable, runnable);
        }
    };
    AbstractDynamicDistributionForm setupForm = new DynamicDistributionDetailsForm(parent, SWT.NONE, getDynamicBuildConfigurationData(), monitor);
    setupForm.setCheckListener(checkListener);
    setControl(setupForm);
    setCurrentForm(setupForm);
    setPageComplete(false);
}
Also used : ICheckListener(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm.ICheckListener) ICheckListener(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm.ICheckListener) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) AbstractDynamicDistributionForm(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm) DynamicDistributionDetailsForm(org.talend.repository.hadoopcluster.ui.dynamic.form.DynamicDistributionDetailsForm) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 9 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class DynamicDistributionPreferencePage method createContents.

@Override
protected Control createContents(Composite parent) {
    AbstractDynamicDistributionForm.ICheckListener checkListener = new ICheckListener() {

        @Override
        public String getMessage() {
            return DynamicDistributionPreferencePage.this.getMessage();
        }

        @Override
        public void showMessage(String message, int level) {
            setMessage(message, level);
        }

        @Override
        public void updateButtons() {
            boolean isValid = getCurrentForm().isComplete();
            setValid(isValid);
        }

        @Override
        public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws Exception {
            // $NON-NLS-1$
            throw new Exception("Please implement it if needed");
        }
    };
    IDynamicMonitor monitor = new DummyDynamicMonitor();
    DynamicDistributionPreferenceForm existingConfigForm = new DynamicDistributionPreferenceForm(parent, SWT.NONE, monitor, ITalendCorePrefConstants.DYNAMIC_DISTRIBUTION_SETTING);
    existingConfigForm.setCheckListener(checkListener);
    setCurrentForm(existingConfigForm);
    boolean isValid = getCurrentForm().isComplete();
    setValid(isValid);
    return existingConfigForm;
}
Also used : ICheckListener(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm.ICheckListener) ICheckListener(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm.ICheckListener) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) AbstractDynamicDistributionForm(org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm) DynamicDistributionPreferenceForm(org.talend.repository.hadoopcluster.ui.dynamic.form.DynamicDistributionPreferenceForm) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 10 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class DynamicDistributionDetailsForm method onExportConfigurationSelected.

private void onExportConfigurationSelected() {
    DirectoryDialog dirDialog = new DirectoryDialog(getShell());
    String folderPath = dirDialog.open();
    if (StringUtils.isNotEmpty(folderPath)) {
        try {
            // IDynamicPlugin dynamicPlugin = getDynamicDistributionSetupData().getDynamicPlugin();
            IDynamicPlugin dynamicPlugin = newDynamicPluginCache;
            IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
            String id = pluginConfiguration.getId();
            // $NON-NLS-1$
            String fileName = id + "." + DynamicDistributionManager.DISTRIBUTION_FILE_EXTENSION;
            // $NON-NLS-1$
            String filePath = folderPath + "/" + fileName;
            File file = new File(filePath);
            if (file.exists()) {
                boolean agree = MessageDialog.openQuestion(getShell(), // $NON-NLS-1$
                Messages.getString("DynamicDistributionDetailsForm.exportConfig.dialog.fileExist.title"), // $NON-NLS-1$
                Messages.getString(// $NON-NLS-1$
                "DynamicDistributionDetailsForm.exportConfig.dialog.fileExist.message", file.getCanonicalPath()));
                if (!agree) {
                    return;
                }
            }
            IDynamicMonitor monitor = new DummyDynamicMonitor();
            DynamicDistributionManager.getInstance().saveUsersDynamicPlugin(dynamicPlugin, filePath, monitor);
            MessageDialog.openInformation(getShell(), // $NON-NLS-1$
            Messages.getString("DynamicDistributionDetailsForm.exportConfig.dialog.title"), // $NON-NLS-1$
            Messages.getString(// $NON-NLS-1$
            "DynamicDistributionDetailsForm.exportConfig.dialog.message", new File(filePath).getCanonicalPath()));
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) File(java.io.File) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Aggregations

DummyDynamicMonitor (org.talend.designer.maven.aether.DummyDynamicMonitor)13 IDynamicMonitor (org.talend.designer.maven.aether.IDynamicMonitor)10 IDynamicPlugin (org.talend.core.runtime.dynamic.IDynamicPlugin)6 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)5 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 AbstractDynamicDistributionForm (org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm)4 ICheckListener (org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm.ICheckListener)4 LinkedList (java.util.LinkedList)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 VersionStringComparator (org.talend.designer.maven.aether.comparator.VersionStringComparator)2 DynamicDistributionSetupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData)2 DynamicDistributionPreferenceForm (org.talend.repository.hadoopcluster.ui.dynamic.form.DynamicDistributionPreferenceForm)2 File (java.io.File)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1