Search in sources :

Example 1 with RunOnServerActionDelegate

use of org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate in project webtools.servertools by eclipse.

the class ServersViewDropAdapter method doSel.

protected boolean doSel(IServer server, Object data) {
    // check if the selection is a project (module) that we can add to the server
    IProject project = (IProject) Platform.getAdapterManager().getAdapter(data, IProject.class);
    if (project != null) {
        IModule[] modules = ServerUtil.getModules(project);
        if (modules != null && modules.length == 1) {
            try {
                IServerWorkingCopy wc = server.createWorkingCopy();
                IModule[] parents = wc.getRootModules(modules[0], null);
                if (parents == null || parents.length == 0)
                    return false;
                if (ServerUtil.containsModule(server, parents[0], null))
                    return false;
                IModule[] add = new IModule[] { parents[0] };
                if (wc.canModifyModules(add, null, null).getSeverity() != IStatus.ERROR) {
                    wc.modifyModules(modules, null, null);
                    wc.save(false, null);
                    return true;
                }
            } catch (final CoreException ce) {
                final Shell shell = getViewer().getControl().getShell();
                shell.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        EclipseUtil.openError(shell, ce.getLocalizedMessage());
                    }
                });
                return true;
            }
        }
    }
    // otherwise, try Run on Server
    final IServer finalServer = server;
    RunOnServerActionDelegate ros = new RunOnServerActionDelegate() {

        public IServer getServer(IModule module, IModuleArtifact moduleArtifact, IProgressMonitor monitor) throws CoreException {
            if (!ServerUIPlugin.isCompatibleWithLaunchMode(finalServer, launchMode))
                return null;
            if (!ServerUtil.containsModule(finalServer, module, monitor)) {
                IServerWorkingCopy wc = finalServer.createWorkingCopy();
                try {
                    ServerUtil.modifyModules(wc, new IModule[] { module }, new IModule[0], monitor);
                    wc.save(false, monitor);
                } catch (CoreException ce) {
                    throw ce;
                }
            }
            return finalServer;
        }
    };
    Action action = new Action() {
    };
    ros.selectionChanged(action, new StructuredSelection(data));
    // if (!action.isEnabled())
    // return false;
    ros.run(action);
    return true;
}
Also used : IModule(org.eclipse.wst.server.core.IModule) IServer(org.eclipse.wst.server.core.IServer) RunOnServerActionDelegate(org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate) Action(org.eclipse.jface.action.Action) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IServerWorkingCopy(org.eclipse.wst.server.core.IServerWorkingCopy) IModuleArtifact(org.eclipse.wst.server.core.IModuleArtifact)

Example 2 with RunOnServerActionDelegate

use of org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate in project webtools.servertools by eclipse.

the class ServerActionHandler method execute.

public Object execute(ExecutionEvent event) throws ExecutionException {
    ISelection sel = HandlerUtil.getCurrentSelectionChecked(event);
    Object obj = null;
    if (sel instanceof IStructuredSelection) {
        IStructuredSelection select = (IStructuredSelection) sel;
        obj = select.getFirstElement();
    }
    String id = event.getCommand().getId();
    if (id.endsWith("publish")) {
        if (obj instanceof IServer) {
            PublishAction.publish((IServer) obj, HandlerUtil.getActiveShell(event));
        } else
            throw new ExecutionException("No server selected");
        return null;
    }
    String mode = ILaunchManager.RUN_MODE;
    if (id.endsWith("debug"))
        mode = ILaunchManager.DEBUG_MODE;
    else if (id.endsWith("profile"))
        mode = ILaunchManager.PROFILE_MODE;
    else if (id.endsWith("stop"))
        mode = null;
    if (obj instanceof IServer) {
        IServer server = (IServer) obj;
        if (mode == null)
            StopAction.stop(server, HandlerUtil.getActiveShell(event));
        else
            StartAction.start(server, mode, HandlerUtil.getActiveShell(event));
        return null;
    }
    RunOnServerActionDelegate ros = new RunOnServerActionDelegate();
    ros.setLaunchMode(mode);
    IAction action = new Action() {
    };
    ros.selectionChanged(action, sel);
    ros.run(action);
    return null;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) RunOnServerActionDelegate(org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 3 with RunOnServerActionDelegate

use of org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate in project webtools.servertools by eclipse.

the class ServerUIPlugin method runOnServer.

public static void runOnServer(Object object, String launchMode) {
    RunOnServerActionDelegate delegate = new RunOnServerActionDelegate();
    Action action = new Action() {
    };
    if (object != null) {
        StructuredSelection sel = new StructuredSelection(object);
        delegate.selectionChanged(action, sel);
    } else
        delegate.selectionChanged(action, null);
    delegate.run(action);
}
Also used : RunOnServerActionDelegate(org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate) Action(org.eclipse.jface.action.Action) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 4 with RunOnServerActionDelegate

use of org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate in project webtools.servertools by eclipse.

the class ServerLaunchShortcut method launch.

/* (non-Javadoc)
	 * @see ILaunchShortcut#launch(ISelection, String)
	 */
public void launch(ISelection selection, final String mode) {
    RunOnServerActionDelegate ros = new RunOnServerActionDelegate();
    ros.setLaunchMode(mode);
    IAction action = new Action() {
    };
    ros.selectionChanged(action, selection);
    ros.run(action);
}
Also used : RunOnServerActionDelegate(org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate) IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction)

Example 5 with RunOnServerActionDelegate

use of org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate in project webtools.servertools by eclipse.

the class ServersViewDropAdapterAssistant method doRunOnServerAction.

protected boolean doRunOnServerAction(IServer server, Object data) {
    // check if the selection is a project (module) that we can add to the server
    IProject project = (IProject) Platform.getAdapterManager().getAdapter(data, IProject.class);
    if (project != null) {
        IModule[] modules = ServerUtil.getModules(project);
        if (modules != null && modules.length == 1) {
            try {
                IServerWorkingCopy wc = server.createWorkingCopy();
                IModule[] parents = wc.getRootModules(modules[0], null);
                if (parents == null || parents.length == 0)
                    return false;
                if (ServerUtil.containsModule(server, parents[0], null)) {
                    PublishAction.publish(server, getShell());
                    return false;
                }
                IModule[] add = new IModule[] { parents[0] };
                if (wc.canModifyModules(add, null, null).getSeverity() != IStatus.ERROR) {
                    wc.modifyModules(modules, null, null);
                    wc.save(false, null);
                    PublishAction.publish(server, getShell());
                    return true;
                }
            } catch (final CoreException ce) {
                final Shell shell = getShell();
                shell.getDisplay().asyncExec(new Runnable() {

                    public void run() {
                        EclipseUtil.openError(shell, ce.getLocalizedMessage());
                    }
                });
                return true;
            }
        }
    }
    // otherwise, try Run on Server
    final IServer finalServer = server;
    RunOnServerActionDelegate ros = new RunOnServerActionDelegate() {

        public IServer getServer(IModule module, IModuleArtifact moduleArtifact, IProgressMonitor monitor) throws CoreException {
            if (!ServerUIPlugin.isCompatibleWithLaunchMode(finalServer, launchMode))
                return null;
            if (!ServerUtil.containsModule(finalServer, module, monitor)) {
                IServerWorkingCopy wc = finalServer.createWorkingCopy();
                try {
                    ServerUtil.modifyModules(wc, new IModule[] { module }, new IModule[0], monitor);
                    wc.save(false, monitor);
                } catch (CoreException ce) {
                    throw ce;
                }
            }
            return finalServer;
        }
    };
    Action action = new Action() {
    };
    ros.selectionChanged(action, new StructuredSelection(data));
    ros.run(action);
    return true;
}
Also used : RunOnServerActionDelegate(org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate) Action(org.eclipse.jface.action.Action) PublishAction(org.eclipse.wst.server.ui.internal.view.servers.PublishAction) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IProject(org.eclipse.core.resources.IProject) Shell(org.eclipse.swt.widgets.Shell)

Aggregations

Action (org.eclipse.jface.action.Action)5 RunOnServerActionDelegate (org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 IProject (org.eclipse.core.resources.IProject)2 IAction (org.eclipse.jface.action.IAction)2 Shell (org.eclipse.swt.widgets.Shell)2 IServer (org.eclipse.wst.server.core.IServer)2 ExecutionException (org.eclipse.core.commands.ExecutionException)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IModule (org.eclipse.wst.server.core.IModule)1 IModuleArtifact (org.eclipse.wst.server.core.IModuleArtifact)1 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)1 PublishAction (org.eclipse.wst.server.ui.internal.view.servers.PublishAction)1