Search in sources :

Example 1 with IServerModule

use of org.eclipse.wst.server.ui.IServerModule in project sling by apache.

the class ServersActionModeFiddlerActionDelegate method selectionChanged.

@Override
public void selectionChanged(IAction action, ISelection selection) {
    server = null;
    modules = null;
    if (selection != null && (selection instanceof IStructuredSelection)) {
        IStructuredSelection iss = (IStructuredSelection) selection;
        Object first = iss.getFirstElement();
        if (first instanceof IServer) {
            server = (IServer) first;
            modules = null;
            if (iss.size() > 1) {
                // verify that all selected elements are of type IServer
                Iterator<?> it = iss.iterator();
                // skip the first, we have that above already
                it.next();
                while (it.hasNext()) {
                    Object next = it.next();
                    if (!(next instanceof IServer)) {
                        server = null;
                        modules = null;
                        break;
                    }
                }
            }
        } else if (first instanceof IServerModule) {
            modules = new LinkedList<>();
            IServerModule module = (IServerModule) first;
            modules.add(module.getModule());
            server = module.getServer();
            if (iss.size() > 1) {
                // verify that all selected elements are of type IServerModule
                // plus add the module[] to the modules list
                Iterator<?> it = iss.iterator();
                // skip the first, we have that above already
                it.next();
                while (it.hasNext()) {
                    Object next = it.next();
                    if (!(next instanceof IServerModule)) {
                        server = null;
                        module = null;
                        break;
                    } else {
                        module = (IServerModule) next;
                        modules.add(module.getModule());
                    }
                }
            }
        }
    }
    if (server != null) {
        if (server.getServerState() != IServer.STATE_STARTED) {
            server = null;
            modules = null;
        }
    }
    cleanAction.setEnabled(server != null);
    publishAction.setEnabled(server != null);
    action.setEnabled(true);
    final IAction serverRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.run");
    final IAction serverDebugAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.debug");
    IAction stopRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.stop");
    if (serverRunAction == null || stopRunAction == null || serverDebugAction == null) {
        return;
    }
    //		serverRunAction.setHoverImageDescriptor(SharedImages.SLING_LOG);
    serverRunAction.setHoverImageDescriptor(SharedImages.RUN_CONNECT);
    serverDebugAction.setHoverImageDescriptor(SharedImages.DEBUG_CONNECT);
    stopRunAction.setHoverImageDescriptor(SharedImages.DISCONNECT);
    findWstPublishAction();
    for (ActionContributionItem appendedAction : appendedToolbarActionContributionItems) {
        if (!contributionAdded(appendedAction)) {
            actionBars.getToolBarManager().add(appendedAction);
        }
    }
    if (wstPublishAction != null) {
        wstPublishAction.setVisible(false);
        publishActionContributionItem.setVisible(true);
    } else {
        // otherwise hide it, as it is an unexpected situation
        publishActionContributionItem.setVisible(false);
    }
    final String runText = "Connect to server in run mode";
    if (runTooltipListener == null) {
        runTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(runText)) {
                        serverRunAction.setToolTipText(runText);
                    }
                }
            }
        };
        serverRunAction.addPropertyChangeListener(runTooltipListener);
    }
    final String debugText = "Connect to server in debug mode";
    if (debugTooltipListener == null) {
        debugTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(debugText)) {
                        serverDebugAction.setToolTipText(debugText);
                    }
                }
            }
        };
        serverDebugAction.addPropertyChangeListener(debugTooltipListener);
    }
    final String disconnectText = "Disconnect from server";
    if (disconnectTooltipListener == null) {
        disconnectTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(disconnectText)) {
                        serverRunAction.setToolTipText(disconnectText);
                    }
                }
            }
        };
        stopRunAction.addPropertyChangeListener(disconnectTooltipListener);
    }
    serverRunAction.setToolTipText(runText);
    serverDebugAction.setToolTipText(debugText);
    stopRunAction.setToolTipText(disconnectText);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) IServer(org.eclipse.wst.server.core.IServer) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IAction(org.eclipse.jface.action.IAction) IServerModule(org.eclipse.wst.server.ui.IServerModule) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LinkedList(java.util.LinkedList) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) Iterator(java.util.Iterator)

Aggregations

Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)1 IAction (org.eclipse.jface.action.IAction)1 IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)1 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IServer (org.eclipse.wst.server.core.IServer)1 IServerModule (org.eclipse.wst.server.ui.IServerModule)1