Search in sources :

Example 96 with IServer

use of org.eclipse.wst.server.core.IServer in project sling by apache.

the class ServersActionModeFiddlerActionDelegate method selectionChanged.

@Override
public void selectionChanged(IAction action, ISelection selection) {
    server = null;
    modules = null;
    if (selection != null && (selection instanceof IStructuredSelection)) {
        IStructuredSelection iss = (IStructuredSelection) selection;
        Object first = iss.getFirstElement();
        if (first instanceof IServer) {
            server = (IServer) first;
            modules = null;
            if (iss.size() > 1) {
                // verify that all selected elements are of type IServer
                Iterator<?> it = iss.iterator();
                // skip the first, we have that above already
                it.next();
                while (it.hasNext()) {
                    Object next = it.next();
                    if (!(next instanceof IServer)) {
                        server = null;
                        modules = null;
                        break;
                    }
                }
            }
        } else if (first instanceof IServerModule) {
            modules = new LinkedList<>();
            IServerModule module = (IServerModule) first;
            modules.add(module.getModule());
            server = module.getServer();
            if (iss.size() > 1) {
                // verify that all selected elements are of type IServerModule
                // plus add the module[] to the modules list
                Iterator<?> it = iss.iterator();
                // skip the first, we have that above already
                it.next();
                while (it.hasNext()) {
                    Object next = it.next();
                    if (!(next instanceof IServerModule)) {
                        server = null;
                        module = null;
                        break;
                    } else {
                        module = (IServerModule) next;
                        modules.add(module.getModule());
                    }
                }
            }
        }
    }
    if (server != null) {
        if (server.getServerState() != IServer.STATE_STARTED) {
            server = null;
            modules = null;
        }
    }
    cleanAction.setEnabled(server != null);
    publishAction.setEnabled(server != null);
    action.setEnabled(true);
    final IAction serverRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.run");
    final IAction serverDebugAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.debug");
    IAction stopRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.stop");
    if (serverRunAction == null || stopRunAction == null || serverDebugAction == null) {
        return;
    }
    //		serverRunAction.setHoverImageDescriptor(SharedImages.SLING_LOG);
    serverRunAction.setHoverImageDescriptor(SharedImages.RUN_CONNECT);
    serverDebugAction.setHoverImageDescriptor(SharedImages.DEBUG_CONNECT);
    stopRunAction.setHoverImageDescriptor(SharedImages.DISCONNECT);
    findWstPublishAction();
    for (ActionContributionItem appendedAction : appendedToolbarActionContributionItems) {
        if (!contributionAdded(appendedAction)) {
            actionBars.getToolBarManager().add(appendedAction);
        }
    }
    if (wstPublishAction != null) {
        wstPublishAction.setVisible(false);
        publishActionContributionItem.setVisible(true);
    } else {
        // otherwise hide it, as it is an unexpected situation
        publishActionContributionItem.setVisible(false);
    }
    final String runText = "Connect to server in run mode";
    if (runTooltipListener == null) {
        runTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(runText)) {
                        serverRunAction.setToolTipText(runText);
                    }
                }
            }
        };
        serverRunAction.addPropertyChangeListener(runTooltipListener);
    }
    final String debugText = "Connect to server in debug mode";
    if (debugTooltipListener == null) {
        debugTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(debugText)) {
                        serverDebugAction.setToolTipText(debugText);
                    }
                }
            }
        };
        serverDebugAction.addPropertyChangeListener(debugTooltipListener);
    }
    final String disconnectText = "Disconnect from server";
    if (disconnectTooltipListener == null) {
        disconnectTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(disconnectText)) {
                        serverRunAction.setToolTipText(disconnectText);
                    }
                }
            }
        };
        stopRunAction.addPropertyChangeListener(disconnectTooltipListener);
    }
    serverRunAction.setToolTipText(runText);
    serverDebugAction.setToolTipText(debugText);
    stopRunAction.setToolTipText(disconnectText);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) IServer(org.eclipse.wst.server.core.IServer) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IAction(org.eclipse.jface.action.IAction) IServerModule(org.eclipse.wst.server.ui.IServerModule) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LinkedList(java.util.LinkedList) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) Iterator(java.util.Iterator)

Example 97 with IServer

use of org.eclipse.wst.server.core.IServer in project sling by apache.

the class SlingLaunchpadCombo method refreshRepositoryList.

public void refreshRepositoryList(IProgressMonitor monitor) {
    repositoryCombo.removeAll();
    List<IServer> servers = project != null ? SelectionUtils.getServersLinkedToProject(project, monitor) : Arrays.asList(ServerCore.getServers());
    for (IServer server : servers) {
        repositoryCombo.add(server.getId());
    }
    if (servers.size() > 0) {
        repositoryCombo.select(0);
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer)

Example 98 with IServer

use of org.eclipse.wst.server.core.IServer in project sling by apache.

the class AbstractNewSlingApplicationWizard method publishModules.

protected void publishModules(final List<IProject> createdProjects, IProgressMonitor monitor) throws CoreException {
    IServer server = setupServerWizardPage.getOrCreateServer(monitor);
    if (server == null) {
        return;
    }
    if (setupServerWizardPage.getStartServer()) {
        server.start(ILaunchManager.RUN_MODE, monitor);
    }
    List<IModule[]> modules = new ArrayList<>();
    for (IProject project : createdProjects) {
        IModule module = ServerUtil.getModule(project);
        if (module != null && shouldDeploy(module)) {
            modules.add(new IModule[] { module });
        }
    }
    if (modules.size() > 0) {
        server.publish(IServer.PUBLISH_CLEAN, modules, null, null);
    }
}
Also used : IServer(org.eclipse.wst.server.core.IServer) IModule(org.eclipse.wst.server.core.IModule) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject)

Example 99 with IServer

use of org.eclipse.wst.server.core.IServer in project sling by apache.

the class ImportWizard method performFinish.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.wizard.Wizard#performFinish()
	 */
public boolean performFinish() {
    if (!mainPage.isPageComplete()) {
        return false;
    }
    final IServer server = mainPage.getServer();
    IResource resource = mainPage.getResource();
    final IProject project = resource.getProject();
    final IPath projectRelativePath = resource.getProjectRelativePath();
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                // following this change ( see org.apache.sling.ide.core.ResourceUtil )
                try {
                    ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() {

                        @Override
                        public void run(IProgressMonitor monitor) throws CoreException {
                            try {
                                new ImportRepositoryContentAction(server, projectRelativePath, project, serializationManager).run(monitor);
                            } catch (SerializationException e) {
                                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import failed", e));
                            } catch (InvocationTargetException e) {
                                throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Import failed", e.getCause()));
                            } catch (InterruptedException e) {
                                Thread.currentThread().interrupt();
                            } finally {
                                serializationManager.destroy();
                            }
                        }
                    }, project, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        mainPage.setErrorMessage("Import error : " + cause.getMessage() + " . Please see the error log for details.");
        Activator.getDefault().getPluginLogger().error("Repository import failed", cause);
        return false;
    } catch (OperationCanceledException | InterruptedException e) {
        Thread.currentThread().interrupt();
        return false;
    }
    return true;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IServer(org.eclipse.wst.server.core.IServer) SerializationException(org.apache.sling.ide.serialization.SerializationException) IPath(org.eclipse.core.runtime.IPath) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ImportRepositoryContentAction(org.apache.sling.ide.eclipse.ui.internal.ImportRepositoryContentAction) IResource(org.eclipse.core.resources.IResource)

Example 100 with IServer

use of org.eclipse.wst.server.core.IServer in project sling by apache.

the class NewSlingContentProjectWizard method configureCreatedProjects.

@Override
protected Projects configureCreatedProjects(List<IProject> createdProjects, IProgressMonitor monitor) throws CoreException {
    Projects projects = new Projects();
    for (IProject project : createdProjects) {
        ConfigurationHelper.convertToContentPackageProject(project, monitor, new Path("jcr_root"));
        projects.getContentProjects().add(project);
    }
    IServer server = getSetupServerWizardPage().getOrCreateServer(monitor);
    advance(monitor, 1);
    finishConfiguration(createdProjects, server, monitor);
    advance(monitor, 1);
    return projects;
}
Also used : Path(org.eclipse.core.runtime.Path) IServer(org.eclipse.wst.server.core.IServer) IProject(org.eclipse.core.resources.IProject)

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