Search in sources :

Example 1 with IModuleArtifact

use of org.eclipse.wst.server.core.IModuleArtifact 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 IModuleArtifact

use of org.eclipse.wst.server.core.IModuleArtifact in project webtools.servertools by eclipse.

the class IModuleArtifactTestCase method testCreate.

public void testCreate() {
    artifact = new IModuleArtifact() {

        public IModule getModule() {
            return null;
        }
    };
    artifact.getModule();
}
Also used : IModule(org.eclipse.wst.server.core.IModule) IModuleArtifact(org.eclipse.wst.server.core.IModuleArtifact)

Aggregations

IModule (org.eclipse.wst.server.core.IModule)2 IModuleArtifact (org.eclipse.wst.server.core.IModuleArtifact)2 IProject (org.eclipse.core.resources.IProject)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 Action (org.eclipse.jface.action.Action)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Shell (org.eclipse.swt.widgets.Shell)1 IServer (org.eclipse.wst.server.core.IServer)1 IServerWorkingCopy (org.eclipse.wst.server.core.IServerWorkingCopy)1 RunOnServerActionDelegate (org.eclipse.wst.server.ui.internal.actions.RunOnServerActionDelegate)1