Skip to content

Commit

Permalink
[JBIDE-18827] added start/stop to application/server context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Jan 7, 2015
1 parent 2674949 commit 6afa5fe
Show file tree
Hide file tree
Showing 13 changed files with 449 additions and 68 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ openshift.command.application.new = Application...
openshift.command.application.import = Import Application...
openshift.command.application.delete = Delete Application(s)...
openshift.command.application.restart = Restart Application
openshift.command.application.start = Start Application
openshift.command.application.stop = Stop Application
openshift.command.application.editcartridges = Edit Embedded Cartridges...
openshift.command.application.envvars = Edit User Environment Variables...
openshift.command.application.details = Details...
Expand Down
126 changes: 124 additions & 2 deletions plugins/org.jboss.tools.openshift.express.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,130 @@
</command>
</menuContribution>
</extension>

<!-- manage keys -->

<!-- start application -->
<extension
point="org.eclipse.ui.commands">
<command
id="org.jboss.tools.openshift.express.ui.command.startApplication"
name="%openshift.command.application.start">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.jboss.tools.openshift.express.internal.ui.command.StartApplicationHandler"
commandId="org.jboss.tools.openshift.express.ui.command.startApplication">
</handler>
</extension>
<!-- openshift explorer: start application -->
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.jboss.tools.openshift.express.ui.explorer.expressConsoleView.popup?after=group.modify">
<command
commandId="org.jboss.tools.openshift.express.ui.command.startApplication"
icon="icons/lrun_obj.gif"
id="org.jboss.tools.openshift.express.ui.command.startApplication"
mnemonic="S">
<visibleWhen>
<with variable="selection">
<and>
<count value="1" />
<iterate ifEmpty="false" operator="or">
<instanceof
value="com.openshift.client.IApplication" />
</iterate>
</and>
</with>
</visibleWhen>
</command>
</menuContribution>
<!-- servers view: start application -->
<menuContribution
locationURI="popup:org.jboss.tools.openshift.express.serverviewer.openshift?after=group.modify">
<command
commandId="org.jboss.tools.openshift.express.ui.command.startApplication"
icon="icons/lrun_obj.gif"
id="org.jboss.tools.openshift.express.ui.command.startApplication"
mnemonic="S">
<visibleWhen>
<with variable="selection">
<and>
<count value="1" />
<iterate ifEmpty="false" operator="or">
<instanceof
value="org.eclipse.wst.server.core.IServer" />
</iterate>
</and>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>

<!-- stop application -->
<extension
point="org.eclipse.ui.commands">
<command
id="org.jboss.tools.openshift.express.ui.command.stopApplication"
name="%openshift.command.application.stop">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="org.jboss.tools.openshift.express.internal.ui.command.StopApplicationHandler"
commandId="org.jboss.tools.openshift.express.ui.command.stopApplication">
</handler>
</extension>
<!-- openshift explorer: stop application -->
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.jboss.tools.openshift.express.ui.explorer.expressConsoleView.popup?after=group.modify">
<command
commandId="org.jboss.tools.openshift.express.ui.command.stopApplication"
icon="icons/terminatedlaunch_obj.gif"
id="org.jboss.tools.openshift.express.ui.command.stopApplication"
mnemonic="T">
<visibleWhen>
<with variable="selection">
<and>
<count value="1" />
<iterate ifEmpty="false" operator="or">
<instanceof
value="com.openshift.client.IApplication" />
</iterate>
</and>
</with>
</visibleWhen>
</command>
</menuContribution>
<!-- servers view: stop application -->
<menuContribution
locationURI="popup:org.jboss.tools.openshift.express.serverviewer.openshift?after=group.modify">
<command
commandId="org.jboss.tools.openshift.express.ui.command.stopApplication"
icon="icons/terminatedlaunch_obj.gif"
id="org.jboss.tools.openshift.express.ui.command.stopApplication"
mnemonic="S">
<visibleWhen>
<with variable="selection">
<and>
<count value="1" />
<iterate ifEmpty="false" operator="or">
<instanceof
value="org.eclipse.wst.server.core.IServer" />
</iterate>
</and>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>

<!-- manage keys -->
<extension
point="org.eclipse.ui.commands">
<command
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (c) 2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.command;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.wst.server.core.IServer;
import org.jboss.tools.openshift.express.internal.core.server.OpenShiftServerUtils;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.job.LoadApplicationJob;
import org.jboss.tools.openshift.express.internal.ui.utils.UIUtils;

import com.openshift.client.IApplication;
import com.openshift.internal.client.utils.StringUtils;

/**
* @author Andre Dietisheim
*/
public abstract class AbstractApplicationHandler extends AbstractHandler {

public Object execute(final ExecutionEvent event) throws ExecutionException {
IApplication application = UIUtils.getFirstElement(HandlerUtil.getCurrentSelection(event), IApplication.class);
Shell shell = HandlerUtil.getActiveShell(event);
if (application != null) {
return execute(application, shell);
} else {
IServer server = UIUtils.getFirstElement(HandlerUtil.getCurrentSelection(event), IServer.class);
if (server == null) {
return OpenShiftUIActivator.createCancelStatus(NLS.bind("Could not {0}: server adapter not found.", getOperationName()));
}
return execute(server, shell);
}
}

protected IStatus execute(IServer server, Shell shell) {
String applicationName = OpenShiftServerUtils.getApplicationName(server);
if (StringUtils.isEmpty(applicationName)) {
return OpenShiftUIActivator.createCancelStatus(NLS.bind(
"Could not {0} application: application for server adapter {1} not found.",
getOperationName(),
server.getName()));
}
return execute(new LoadApplicationJob(server), shell);
}

protected abstract IStatus execute(IApplication application, Shell shell);

protected abstract IStatus execute(LoadApplicationJob loadApplicationJob, Shell shell);

protected abstract String getOperationName();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013 Red Hat, Inc.
* Copyright (c) 2013-2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand All @@ -10,46 +10,25 @@
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.command;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.wst.server.core.IServer;
import org.jboss.tools.openshift.express.internal.core.server.OpenShiftServerUtils;
import org.jboss.tools.openshift.express.internal.core.util.JobChainBuilder;
import org.jboss.tools.openshift.express.internal.ui.OpenShiftUIActivator;
import org.jboss.tools.openshift.express.internal.ui.job.LoadApplicationJob;
import org.jboss.tools.openshift.express.internal.ui.job.RestartApplicationJob;
import org.jboss.tools.openshift.express.internal.ui.utils.UIUtils;

import com.openshift.client.IApplication;
import com.openshift.internal.client.utils.StringUtils;

/**
* @author Andre Dietisheim
*/
public class RestartApplicationHandler extends AbstractHandler {
public class RestartApplicationHandler extends AbstractApplicationHandler {

public Object execute(final ExecutionEvent event) throws ExecutionException {
IApplication application = UIUtils.getFirstElement(HandlerUtil.getCurrentSelection(event), IApplication.class);
Shell shell = HandlerUtil.getActiveShell(event);
if (application != null) {
return restartFor(application, shell);
} else {
IServer server = UIUtils.getFirstElement(HandlerUtil.getCurrentSelection(event), IServer.class);
if (server == null) {
return OpenShiftUIActivator.createCancelStatus("Could not restart application: server adapter not found.");
}
return restartFor(server, shell);
}
}

private Object restartFor(IApplication application, Shell shell) {
@Override
protected IStatus execute(IApplication application, Shell shell) {
if (!promptUserToConfirm(application.getName(), shell)) {
return OpenShiftUIActivator.createCancelStatus(
"Restarting application {0} was cancelled.", application.getName());
Expand All @@ -58,20 +37,14 @@ private Object restartFor(IApplication application, Shell shell) {
return Status.OK_STATUS;
}

private IStatus restartFor(IServer server, Shell shell) {
String applicationName = OpenShiftServerUtils.getApplicationName(server);
if (StringUtils.isEmpty(applicationName)) {
return OpenShiftUIActivator.createCancelStatus(NLS.bind(
"Could not restart application: application for server adapter {0} not found.",
server.getName()));
}
if (!promptUserToConfirm(applicationName, shell)) {
@Override
protected IStatus execute(LoadApplicationJob job, Shell shell) {
if (!promptUserToConfirm(job.getApplicationName(), shell)) {
return OpenShiftUIActivator.createCancelStatus(
"Restarting application {0} was cancelled.", applicationName);
"Restarting application {0} was cancelled.", job.getApplicationName());
}
final LoadApplicationJob applicationJob = new LoadApplicationJob(server);
new JobChainBuilder(applicationJob)
.runWhenSuccessfullyDone(new RestartApplicationJob(applicationJob)).schedule();
new JobChainBuilder(job)
.runWhenSuccessfullyDone(new RestartApplicationJob(job)).schedule();
return Status.OK_STATUS;
}

Expand All @@ -85,4 +58,9 @@ private boolean promptUserToConfirm(String applicationName, Shell shell) {
+ "Are you sure that you want to restart your application?",
applicationName));
}

@Override
protected String getOperationName() {
return "restart application";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.command;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Shell;
import org.jboss.tools.openshift.express.internal.core.util.JobChainBuilder;
import org.jboss.tools.openshift.express.internal.ui.job.LoadApplicationJob;
import org.jboss.tools.openshift.express.internal.ui.job.StartApplicationJob;

import com.openshift.client.IApplication;

/**
* @author Andre Dietisheim
*/
public class StartApplicationHandler extends AbstractApplicationHandler {

@Override
protected IStatus execute(IApplication application, Shell shell) {
new StartApplicationJob(application).schedule();
return Status.OK_STATUS;
}

@Override
protected IStatus execute(LoadApplicationJob job, Shell shell) {
new JobChainBuilder(job)
.runWhenSuccessfullyDone(new StartApplicationJob(job)).schedule();
return Status.OK_STATUS;
}

@Override
protected String getOperationName() {
return "start application";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.express.internal.ui.command;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.swt.widgets.Shell;
import org.jboss.tools.openshift.express.internal.core.util.JobChainBuilder;
import org.jboss.tools.openshift.express.internal.ui.job.LoadApplicationJob;
import org.jboss.tools.openshift.express.internal.ui.job.StopApplicationJob;

import com.openshift.client.IApplication;

/**
* @author Andre Dietisheim
*/
public class StopApplicationHandler extends AbstractApplicationHandler {

@Override
protected IStatus execute(IApplication application, Shell shell) {
new StopApplicationJob(application).schedule();
return Status.OK_STATUS;
}

@Override
protected IStatus execute(LoadApplicationJob job, Shell shell) {
new JobChainBuilder(job)
.runWhenSuccessfullyDone(new StopApplicationJob(job)).schedule();
return Status.OK_STATUS;
}

@Override
protected String getOperationName() {
return "stop application";
}
}

0 comments on commit 6afa5fe

Please sign in to comment.