use of org.eclipse.wst.server.core.IServer 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.core.IServer in project webtools.servertools by eclipse.
the class ServerTableLabelProvider method getColumnImage.
public Image getColumnImage(Object element, int columnIndex) {
if (element instanceof ServerTreeContentProvider.TreeElement) {
if (columnIndex == 0) {
ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
return sharedImages.getImage(ISharedImages.IMG_OBJ_FOLDER);
}
return null;
}
if (element instanceof ModuleServer) {
ModuleServer ms = (ModuleServer) element;
if (columnIndex == 0) {
// return ServerUICore.getLabelProvider().getImage(ms.module[ms.module.length - 1]);
ILabelProvider labelProvider = ServerUICore.getLabelProvider();
Image image = labelProvider.getImage(ms.module[ms.module.length - 1]);
labelProvider.dispose();
if (decorator != null) {
Image dec = decorator.decorateImage(image, ms);
if (dec != null)
return dec;
}
return image;
} else if (columnIndex == 1) {
if (ms.server == null)
return null;
/*int state = ms.server.getModuleState(ms.module);
if (state == IServer.STATE_STARTED)
return ImageResource.getImage(ImageResource.IMG_STATE_STARTED);
else if (state == IServer.STATE_STOPPED)
return ImageResource.getImage(ImageResource.IMG_STATE_STOPPED);
*/
return getStateImage(ms.server.getServerType(), ms.server.getModuleState(ms.module), null);
} else if (columnIndex == 2) {
IStatus status = ((Server) ms.server).getModuleStatus(ms.module);
if (status != null) {
ISharedImages sharedImages = ServerUIPlugin.getInstance().getWorkbench().getSharedImages();
if (status.getSeverity() == IStatus.ERROR)
return sharedImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK);
else if (status.getSeverity() == IStatus.WARNING)
return sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK);
else if (status.getSeverity() == IStatus.INFO)
return sharedImages.getImage(ISharedImages.IMG_OBJS_INFO_TSK);
}
}
return null;
}
IServer server = (IServer) element;
if (columnIndex == 0) {
if (server.getServerType() != null) {
Image image = ImageResource.getImage(server.getServerType().getId());
// return image;
if (decorator != null) {
Image dec = decorator.decorateImage(image, server);
if (dec != null)
return dec;
}
return image;
}
return null;
} else if (columnIndex == 1) {
IServerType serverType = server.getServerType();
if (serverType == null)
return null;
// return null;
return getServerStateImage(server);
} else
return null;
}
use of org.eclipse.wst.server.core.IServer in project webtools.servertools by eclipse.
the class ServerTableLabelProvider method getColumnText.
public String getColumnText(Object element, int columnIndex) {
if (element instanceof ServerTreeContentProvider.TreeElement) {
if (columnIndex == 0)
return ((ServerTreeContentProvider.TreeElement) element).text;
return "";
}
if (element instanceof ModuleServer) {
ModuleServer ms = (ModuleServer) element;
if (columnIndex == 0) {
if (ms.module == null)
return "";
int size = ms.module.length;
String name = ms.module[size - 1].getName();
if (decorator != null) {
String dec = decorator.decorateText(name, ms);
if (dec != null)
return dec;
}
return name;
} else if (columnIndex == 1) {
if (ms.server == null)
return "";
return getStateLabel(ms.server.getServerType(), ms.server.getModuleState(ms.module), null);
} else if (columnIndex == 2) {
IStatus status = ((Server) ms.server).getModuleStatus(ms.module);
if (status != null)
return status.getMessage();
return modulePublishState[ms.server.getModulePublishState(ms.module)];
}
}
IServer server = (IServer) element;
if (columnIndex == 0)
return notNull(server.getName());
else if (columnIndex == 1) {
IServerType serverType = server.getServerType();
if (serverType != null)
return getServerStateLabel(server);
return "";
} else if (columnIndex == 2) {
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 (ServerTableViewer.publishing.contains(serverId))
return syncState[4];
// republish
int i = 0;
if (server.shouldPublish()) {
if (((Server) server).isPublishUnknown())
return "";
i += 2;
}
if (server.shouldRestart())
i = 1;
// if (serverType.getServerStateSet() == IServerType.SERVER_STATE_SET_MANAGED)
return syncState[i];
// return syncStateUnmanaged[i];
} else
return "-";
}
use of org.eclipse.wst.server.core.IServer in project webtools.servertools by eclipse.
the class ServerTransfer method nativeToJava.
/* (non-Javadoc)
* @see org.eclipse.swt.dnd.Transfer#nativeToJava(org.eclipse.swt.dnd.TransferData)
*/
protected Object nativeToJava(TransferData transferData) {
byte[] bytes = (byte[]) super.nativeToJava(transferData);
if (bytes == null)
return null;
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
try {
IMemento memento = XMLMemento.loadMemento(in);
IMemento[] children = memento.getChildren("server");
int count = children.length;
IServer[] results = new IServer[count];
for (int i = 0; i < count; i++) {
Server server = new Server(null);
server.deserialize(children[i]);
results[i] = server;
}
return results;
} catch (Exception e) {
DND.error(DND.ERROR_INVALID_DATA);
}
return null;
}
use of org.eclipse.wst.server.core.IServer 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;
}
Aggregations