use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.
the class DynamicDistributionOptionForm method initExistingConfigurationInfos.
private void initExistingConfigurationInfos() throws Exception {
existingConfigurationNames = new HashSet<>();
existingConfigurationIdMap = new HashMap<>();
IDynamicMonitor monitor = new DummyDynamicMonitor();
DynamicDistributionManager dynDistrManager = DynamicDistributionManager.getInstance();
List<IDynamicPlugin> allDynamicPlugins = new LinkedList<>();
List<IDynamicPlugin> allBuiltinDynamicPlugins = dynDistrManager.getAllBuiltinDynamicPlugins(monitor);
if (allBuiltinDynamicPlugins != null && !allBuiltinDynamicPlugins.isEmpty()) {
allDynamicPlugins.addAll(allBuiltinDynamicPlugins);
}
List<IDynamicPlugin> allUsesDynamicPlugins = dynDistrManager.getAllUsersDynamicPlugins(monitor);
if (allUsesDynamicPlugins != null && !allUsesDynamicPlugins.isEmpty()) {
allDynamicPlugins.addAll(allUsesDynamicPlugins);
}
if (allDynamicPlugins != null && !allDynamicPlugins.isEmpty()) {
Iterator<IDynamicPlugin> iter = allDynamicPlugins.iterator();
while (iter.hasNext()) {
IDynamicPlugin dynPlugin = iter.next();
IDynamicPluginConfiguration pluginConfiguration = dynPlugin.getPluginConfiguration();
existingConfigurationNames.add(pluginConfiguration.getName());
existingConfigurationIdMap.put(pluginConfiguration.getId(), dynPlugin);
}
}
}
use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.
the class DynamicDistributionOptionForm method checkImportConfigText.
private boolean checkImportConfigText() {
try {
if (!importConfigBtn.getSelection()) {
return true;
}
StringBuffer messageBuffer = new StringBuffer();
importConfigText.setBackground(null);
importConfigText.setToolTipText(importConfigText.getText());
String importConfig = importConfigText.getText();
if (StringUtils.isEmpty(importConfig)) {
// $NON-NLS-1$
String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.empty");
showMessage(errorMessage, WizardPage.ERROR);
importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
importConfigText.setToolTipText(errorMessage);
return false;
}
if (importedDynamicPlugin == null) {
// $NON-NLS-1$
String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.empty");
importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
importConfigText.setToolTipText(errorMessage);
showMessage(errorMessage, WizardPage.ERROR);
return false;
}
// 1. check plugin configuration
IDynamicPluginConfiguration pluginConfiguration = importedDynamicPlugin.getPluginConfiguration();
if (pluginConfiguration == null) {
// $NON-NLS-1$
String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.noConfiguration");
importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
importConfigText.setToolTipText(errorMessage);
showMessage(errorMessage, WizardPage.ERROR);
return false;
}
DynamicDistributionSetupData dynamicBuildConfigurationData = getDynamicDistributionSetupData();
// 2. check distribution
IDynamicDistributionsGroup dynamicDistributionsGroup = dynamicBuildConfigurationData.getDynamicDistributionsGroup();
if (!dynamicDistributionsGroup.getDistribution().equalsIgnoreCase(pluginConfiguration.getDistribution())) {
String errorMessage = // $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.importConfigText.check.wrongDistribution", pluginConfiguration.getDistribution(), dynamicDistributionsGroup.getDistribution());
importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
importConfigText.setToolTipText(errorMessage);
showMessage(errorMessage, WizardPage.ERROR);
return false;
}
// 3. check id
boolean isIdSame = false;
String id = pluginConfiguration.getId();
if (StringUtils.isEmpty(id)) {
// $NON-NLS-1$
String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.badId.empty");
importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
importConfigText.setToolTipText(errorMessage);
showMessage(errorMessage, WizardPage.ERROR);
return false;
}
if (id.contains(".")) {
// $NON-NLS-1$
String errorMessage = // $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.importConfigText.check.badId.invalid", id);
importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
importConfigText.setToolTipText(errorMessage);
showMessage(errorMessage, WizardPage.ERROR);
return false;
}
IDynamicPlugin existingDynamicPlugin = getDynamicPluginById(id);
if (existingDynamicPlugin != null) {
IDynamicPluginConfiguration existingPluginConfig = existingDynamicPlugin.getPluginConfiguration();
String distribution = existingPluginConfig.getDistribution();
if (!dynamicDistributionsGroup.getDistribution().equalsIgnoreCase(distribution)) {
String errorMessage = Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.importConfigText.check.badId.exist.diffDistribution", // $NON-NLS-1$
id, dynamicDistributionsGroup.getDistribution(), // $NON-NLS-1$
distribution);
importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
importConfigText.setToolTipText(errorMessage);
showMessage(errorMessage, WizardPage.ERROR);
return false;
}
String errorMessage = Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.importConfigText.check.badId.exist.sameDistribution", id);
// $NON-NLS-1$
messageBuffer.append(errorMessage).append("\n");
isIdSame = true;
}
// 4. check name
String name = pluginConfiguration.getName();
if (!isIdSame && isConfigurationNameExist(name)) {
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
String newName = name + // $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.importConfigText.check.badName.exist.desc", date.toString());
pluginConfiguration.setName(newName);
String errorMessage = // $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.importConfigText.check.badName.exist", name, newName);
// $NON-NLS-1$
messageBuffer.append(errorMessage).append("\n");
}
if (0 < messageBuffer.length()) {
String warnMessage = messageBuffer.toString();
importConfigText.setBackground(LoginDialogV2.YELLOW_COLOR);
importConfigText.setToolTipText(warnMessage);
showMessage(warnMessage, WizardPage.WARNING);
}
pluginConfiguration.setAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME, ProjectManager.getInstance().getCurrentProject().getTechnicalLabel());
getDynamicDistributionSetupData().setDynamicPlugin(importedDynamicPlugin);
return true;
} catch (Exception e) {
importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
importConfigText.setToolTipText(e.getMessage());
return false;
}
}
use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.
the class DynamicDistributionOptionForm method createNewDynamicDistribution.
private boolean createNewDynamicDistribution() {
try {
final IDynamicPlugin[] result = new IDynamicPlugin[1];
final Throwable[] throwable = new Throwable[1];
run(true, true, new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
DynamicDistributionSetupData dynConfigData = getDynamicDistributionSetupData();
IDynamicDistributionsGroup dynDistrGroup = dynConfigData.getDynamicDistributionsGroup();
IDynamicMonitor dMonitor = new AbsDynamicProgressMonitor(monitor) {
@Override
public void writeMessage(String message) {
if (isDebuging()) {
System.out.print(message);
}
}
};
// step 1. build dynamic plugin basing on template
dMonitor.beginTask(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicDistributionOptionForm.progress.building", dynamicConfiguration.getName()), IDynamicMonitor.UNKNOWN);
IDynamicPlugin dynamicPlugin = dynDistrGroup.buildDynamicPlugin(dMonitor, dynamicConfiguration);
result[0] = dynamicPlugin;
// step 2. save dynamic plugin and refresh cache
if (dynamicPlugin != null) {
saveDynamicDistribution(dynamicPlugin, dynDistrGroup, ActionType.NewConfig, dMonitor);
}
} catch (Throwable e) {
throwable[0] = e;
}
}
});
if (throwable[0] != null) {
throw throwable[0];
}
IDynamicPlugin newDynamicPlugin = result[0];
if (newDynamicPlugin == null) {
// $NON-NLS-1$
throw new Exception(Messages.getString("DynamicDistributionOptionForm.newConfig.exception.noPluginGenerated"));
}
return true;
} 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 false;
}
use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.
the class DynamicDistributionsLabelProvider method getText.
@Override
public String getText(Object element) {
if (element instanceof IDynamicPlugin) {
IDynamicPluginConfiguration pluginConfiguration = ((IDynamicPlugin) element).getPluginConfiguration();
String name = pluginConfiguration.getName();
String isBuiltinStr = (String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_IS_BUILTIN);
boolean isBuiltin = Boolean.valueOf(isBuiltinStr);
if (isBuiltin) {
// $NON-NLS-1$
name = Messages.getString("DynamicDistributionsLabelProvider.label.existing.builtin", name);
} else {
Project curProj = ProjectManager.getInstance().getCurrentProject();
String curProjTechName = curProj.getTechnicalLabel();
String projTechName = (String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME);
if (StringUtils.equals(curProjTechName, projTechName)) {
// $NON-NLS-1$
name = Messages.getString("DynamicDistributionsLabelProvider.label.existing.currentProject", name);
} else {
name = // $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicDistributionsLabelProvider.label.existing.otherProject", // $NON-NLS-1$
name, projTechName);
}
}
return name;
} else {
// $NON-NLS-1$
return element == null ? "" : element.toString();
}
}
use of org.talend.core.runtime.dynamic.IDynamicPlugin in project tbd-studio-se by Talend.
the class AbstractDynamicDistributionTemplateTest method beforeTest.
@Before
public void beforeTest() throws Exception {
DynamicFactory factory = DynamicFactory.getInstance();
IDynamicPlugin dynamicPlugin = factory.createDynamicPlugin();
IDynamicPluginConfiguration dynamicPluginConfiguration = DynamicFactory.getInstance().createDynamicPluginConfiguration();
dynamicPluginConfiguration.setDistribution(DISTRIBUTION);
// $NON-NLS-1$
dynamicPluginConfiguration.setVersion("v1");
dynamicPlugin.setPluginConfiguration(dynamicPluginConfiguration);
dynamicPluginAdapter = new DynamicPluginAdapter(dynamicPlugin, DynamicCDHDistributionPreferenceFactory.getInstance().getDynamicDistributionPreference(ProjectManager.getInstance().getCurrentProject()), null);
}
Aggregations