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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations