use of org.eclipse.wst.server.core.IServer in project webtools.servertools by eclipse.
the class ServerActionProvider method fillContextMenu.
public void fillContextMenu(IMenuManager menu) {
// This is a temp workaround to clean up the default group that are provided by CNF
menu.removeAll();
ICommonViewerSite site = actionSite.getViewSite();
IStructuredSelection selection = null;
Shell shell = actionSite.getViewSite().getShell();
if (site instanceof ICommonViewerWorkbenchSite) {
ICommonViewerWorkbenchSite wsSite = (ICommonViewerWorkbenchSite) site;
selection = (IStructuredSelection) wsSite.getSelectionProvider().getSelection();
}
IServer server = null;
IModule[] module = null;
ArrayList<IModule> multipleModulesOnOneServer = null;
if (selection != null && !selection.isEmpty()) {
multipleModulesOnOneServer = getMultipleModulesOnOneServer(selection);
Iterator iterator = selection.iterator();
Object obj = iterator.next();
if (obj instanceof IServer)
server = (IServer) obj;
if (obj instanceof ModuleServer) {
ModuleServer ms = (ModuleServer) obj;
server = ms.server;
module = ms.module;
}
if (iterator.hasNext()) {
server = null;
module = null;
}
}
menu.add(invisibleSeparator(TOP_SECTION_START_SEPARATOR));
addTopSection(menu, server, module);
menu.add(invisibleSeparator(TOP_SECTION_END_SEPARATOR));
menu.add(new Separator());
if (server != null && module == null) {
menu.add(invisibleSeparator(EDIT_SECTION_START_SEPARATOR));
menu.add(copyAction);
menu.add(pasteAction);
menu.add(globalDeleteAction);
menu.add(renameAction);
menu.add(invisibleSeparator(EDIT_SECTION_END_SEPARATOR));
menu.add(new Separator());
menu.add(invisibleSeparator(CONTROL_SERVER_SECTION_START_SEPARATOR));
for (int i = 0; i < actions.length; i++) menu.add(actions[i]);
menu.add(invisibleSeparator(CONTROL_SERVER_SECTION_END_SEPARATOR));
menu.add(new Separator());
menu.add(invisibleSeparator(SERVER_ETC_SECTION_START_SEPARATOR));
menu.add(actionModifyModules);
addMonitor(server, menu, shell);
menu.add(invisibleSeparator(SERVER_ETC_SECTION_END_SEPARATOR));
menu.add(new Separator());
} else if (server != null && module != null) {
menu.add(invisibleSeparator(CONTROL_MODULE_SECTION_START_SEPARATOR));
menu.add(new StartModuleAction(server, module));
menu.add(new StopModuleAction(server, module));
menu.add(new RestartModuleAction(server, module));
if (module.length == 1) {
menu.add(new RemoveModuleAction(shell, server, module[0]));
}
menu.add(invisibleSeparator(CONTROL_MODULE_SECTION_END_SEPARATOR));
} else if (server == null && module == null && multipleModulesOnOneServer != null) {
server = selection.getFirstElement() == null ? null : ((ModuleServer) selection.getFirstElement()).getServer();
menu.add(invisibleSeparator(CONTROL_MODULE_SECTION_START_SEPARATOR));
menu.add(new RemoveModuleAction(shell, server, multipleModulesOnOneServer.toArray(new IModule[multipleModulesOnOneServer.size()])));
menu.add(invisibleSeparator(CONTROL_MODULE_SECTION_END_SEPARATOR));
}
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end"));
menu.add(propertiesAction);
}
use of org.eclipse.wst.server.core.IServer in project webtools.servertools by eclipse.
the class ServerActionProvider method addMonitor.
protected void addMonitor(IServer server, IMenuManager menu, Shell shell) {
if (server.getServerType() != null) {
final MenuManager menuManager = new MenuManager(Messages.actionMonitor);
final IServer server2 = server;
final Shell shell2 = shell;
menuManager.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
menuManager.removeAll();
if (server2.getAdapter(ServerDelegate.class) != null) {
ServerPort[] ports = server2.getServerPorts(null);
if (ports != null) {
int size = ports.length;
for (int i = 0; i < size; i++) {
if (!ports[i].isAdvanced())
menuManager.add(new MonitorServerPortAction(shell2, server2, ports[i]));
}
}
}
if (menuManager.isEmpty())
menuManager.add(noneAction);
menuManager.add(new Separator());
menuManager.add(monitorPropertiesAction);
}
});
// add an initial menu item so that the menu appears correctly
noneAction.setEnabled(false);
menuManager.add(noneAction);
menu.add(menuManager);
}
}
use of org.eclipse.wst.server.core.IServer in project webtools.servertools by eclipse.
the class ServerContentProvider method hasChildren.
public boolean hasChildren(Object element) {
if (element instanceof ModuleServer) {
// Check if the module server has child modules.
ModuleServer curModuleServer = (ModuleServer) element;
IServer curServer = curModuleServer.server;
IModule[] curModule = curModuleServer.module;
if (curServer != null && curModule != null) {
IModule[] curChildModule = curServer.getChildModules(curModule, null);
if (curChildModule != null && curChildModule.length > 0)
return true;
return false;
}
return false;
}
if (element instanceof IServer) {
return ((IServer) element).getModules().length > 0;
}
return false;
}
use of org.eclipse.wst.server.core.IServer in project webtools.servertools by eclipse.
the class ServerContentProvider method getChildren.
public Object[] getChildren(Object element) {
if (element instanceof ModuleServer) {
ModuleServer ms = (ModuleServer) element;
try {
IModule[] children = ms.server.getChildModules(ms.module, null);
int size = children.length;
ModuleServer[] ms2 = new ModuleServer[size];
for (int i = 0; i < size; i++) {
int size2 = ms.module.length;
IModule[] module = new IModule[size2 + 1];
System.arraycopy(ms.module, 0, module, 0, size2);
module[size2] = children[i];
ms2[i] = new ModuleServer(ms.server, module);
}
return ms2;
} catch (Exception e) {
return null;
}
}
IServer server = (IServer) element;
IModule[] modules = server.getModules();
int size = modules.length;
ModuleServer[] ms = new ModuleServer[size];
for (int i = 0; i < size; i++) {
ms[i] = new ModuleServer(server, new IModule[] { modules[i] });
}
return ms;
}
use of org.eclipse.wst.server.core.IServer in project webtools.servertools by eclipse.
the class ServerDecorator method getServerStatusLabel.
public static String getServerStatusLabel(IServer server) {
IStatus status = ((Server) server).getServerStatus();
if (status != null)
return status.getMessage();
if (server.getServerType() == null)
return "";
if (server.getServerState() == IServer.STATE_UNKNOWN)
return "";
String serverId = server.getId();
if (ServersView2.publishing.contains(serverId))
return ServerDecorator.syncState[4];
// republish
int i = 0;
if (server.shouldPublish()) {
if (((Server) server).isPublishUnknown())
return "";
i += 2;
}
if (server.shouldRestart())
i = 1;
return syncState[i];
}
Aggregations