Search in sources :

Example 51 with IServer

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);
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IModule(org.eclipse.wst.server.core.IModule) Shell(org.eclipse.swt.widgets.Shell) Iterator(java.util.Iterator)

Example 52 with IServer

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);
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) Shell(org.eclipse.swt.widgets.Shell)

Example 53 with IServer

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;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IModule(org.eclipse.wst.server.core.IModule) ModuleServer(org.eclipse.wst.server.ui.internal.view.servers.ModuleServer)

Example 54 with IServer

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;
}
Also used : IModule(org.eclipse.wst.server.core.IModule) IServer(org.eclipse.wst.server.core.IServer) ModuleServer(org.eclipse.wst.server.ui.internal.view.servers.ModuleServer)

Example 55 with IServer

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];
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IServer(org.eclipse.wst.server.core.IServer) Server(org.eclipse.wst.server.core.internal.Server) ModuleServer(org.eclipse.wst.server.ui.internal.view.servers.ModuleServer)

Aggregations

IServer (org.eclipse.wst.server.core.IServer)183 CoreException (org.eclipse.core.runtime.CoreException)39 IModule (org.eclipse.wst.server.core.IModule)32 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)30 Test (org.junit.Test)30 IProject (org.eclipse.core.resources.IProject)25 IStatus (org.eclipse.core.runtime.IStatus)25 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)23 ArrayList (java.util.ArrayList)20 File (java.io.File)17 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)13 Status (org.eclipse.core.runtime.Status)12 Iterator (java.util.Iterator)11 IPath (org.eclipse.core.runtime.IPath)11 IServerType (org.eclipse.wst.server.core.IServerType)11 CDKServer (org.jboss.tools.openshift.cdk.server.core.internal.adapter.CDKServer)11 IOException (java.io.IOException)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 Server (org.eclipse.wst.server.core.internal.Server)10 IFolder (org.eclipse.core.resources.IFolder)8