rowLayout.marginTop = 0;
rowLayout.marginBottom = 0;
headerComposite.setLayout(rowLayout);
headerComposite.setBackground(null);
ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
toolBarManager.createControl(headerComposite);
applicationsViewer = new TableViewer(toolkit.createTable(client, SWT.NONE));
applicationsViewer.setContentProvider(new TreeContentProvider());
applicationsViewer.setLabelProvider(new ServerLabelProvider() {
@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);
}
}
});
GridDataFactory.fillDefaults().grab(true, true).hint(250, SWT.DEFAULT).applyTo(applicationsViewer.getControl());
int ops = DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT;
Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
ApplicationViewersDropAdapter listener = new ApplicationViewersDropAdapter(applicationsViewer);
applicationsViewer.addDropSupport(ops, transfers, listener);
// create context menu
MenuManager menuManager = new MenuManager();
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
fillApplicationsContextMenu(manager);
}
});
Menu menu = menuManager.createContextMenu(applicationsViewer.getControl());
applicationsViewer.getControl().setMenu(menu);
editorPage.getSite().registerContextMenu(menuManager, applicationsViewer);
Action addRemoveApplicationAction = new Action(Messages.ApplicationMasterPart_TEXT_ADD_REMOVE,
ImageResource.getImageDescriptor(ImageResource.IMG_ETOOL_MODIFY_MODULES)) {
@Override
public void run() {
ModifyModulesWizard wizard = new ModifyModulesWizard(cloudServer.getServerOriginal());
WizardDialog dialog = new WizardDialog(getSection().getShell(), wizard);
dialog.open();
}
};
toolBarManager.add(addRemoveApplicationAction);
// Fix for STS-2996. Moved from CloudFoundryApplicationsEditorPage
toolBarManager.add(new RefreshApplicationEditorAction(editorPage));
toolBarManager.update(true);
section.setTextClient(headerComposite);
getManagedForm().getToolkit().paintBordersFor(client);
}