@Override
public Image getImage(Object element) {
Image image = super.getImage(element);
if (element instanceof IModule) {
IModule module = (IModule) element;
CloudFoundryApplicationModule appModule = editorPage.getCloudServer()
.getExistingCloudModule(module);
if (appModule != null && appModule.getErrorMessage() != null) {
return CloudFoundryImages.getImage(new DecorationOverlayIcon(image,
CloudFoundryImages.OVERLAY_ERROR, IDecoration.BOTTOM_LEFT));
}
}
return image;
}
@Override
public String getText(Object element) {
// This is the WTP module name (usually, it's the workspace
// project name)
String moduleName = super.getText(element);
// However, the user has the option to specify a different name
// when pushing an app, which is used as the cf app name. If
// they are different, and the
// corresponding workspace project is accessible, show both.
// Otherwise, show the cf app name.
if (element instanceof IModule) {
IModule module = (IModule) element;
// Find the corresponding Cloud Foundry-aware application
// Module.
CloudFoundryApplicationModule appModule = cloudServer.getExistingCloudModule((IModule) element);
if (appModule != null) {
String cfAppName = appModule.getDeployedApplicationName();
if (cfAppName != null) {
// Be sure not to show a null WTP module name,
// although
// that should not be encountered
if (moduleName != null
&& !cfAppName.equals(moduleName)
&& CloudFoundryProperties.isModuleProjectAccessible.testProperty(
new IModule[] { module }, cloudServer)) {
moduleName = cfAppName + " (" + moduleName + ")"; //$NON-NLS-1$ //$NON-NLS-2$
}
else {
moduleName = cfAppName;
}
}
}
}
return moduleName;
}
});
applicationsViewer.setInput(new CloudApplication[0]);
applicationsViewer.setSorter(new CloudFoundryViewerSorter());
applicationsViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
IModule module = (IModule) selection.getFirstElement();
if (currentModule != module) {
currentModule = module;
getManagedForm().fireSelectionChanged(ApplicationMasterPart.this, selection);
}