Search in sources :

Example 41 with IServer

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;
}
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 42 with IServer

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IServer(org.eclipse.wst.server.core.IServer) IServer(org.eclipse.wst.server.core.IServer) Server(org.eclipse.wst.server.core.internal.Server) IServerType(org.eclipse.wst.server.core.IServerType) ISharedImages(org.eclipse.ui.ISharedImages) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Image(org.eclipse.swt.graphics.Image)

Example 43 with IServer

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 "-";
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IServer(org.eclipse.wst.server.core.IServer) IServer(org.eclipse.wst.server.core.IServer) Server(org.eclipse.wst.server.core.internal.Server) IServerType(org.eclipse.wst.server.core.IServerType) ServerTreeContentProvider(org.eclipse.wst.server.ui.internal.viewers.ServerTreeContentProvider)

Example 44 with IServer

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;
}
Also used : IServer(org.eclipse.wst.server.core.IServer) Server(org.eclipse.wst.server.core.internal.Server) IServer(org.eclipse.wst.server.core.IServer) ByteArrayInputStream(java.io.ByteArrayInputStream) IMemento(org.eclipse.wst.server.core.internal.IMemento) IOException(java.io.IOException)

Example 45 with IServer

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

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