Search in sources :

Example 1 with CreateServiceWizard

use of org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.CreateServiceWizard in project jbosstools-openshift by jbosstools.

the class CreateServiceHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    ISelection selection = HandlerUtil.getCurrentSelection(event);
    ApplicationElement application = null;
    ProjectElement project = UIUtils.getFirstElement(selection, ProjectElement.class);
    if (project == null) {
        application = UIUtils.getFirstElement(selection, ApplicationElement.class);
        if (application == null) {
            // $NON-NLS-1$
            return OpenShiftUIActivator.statusFactory().cancelStatus("No project or application selected");
        }
        project = application.getParent();
    }
    try {
        Odo odo = project.getParent().getOdo();
        List<ServiceTemplate> templates = odo.getServiceTemplates();
        if (!templates.isEmpty()) {
            final IWizard createServiceWizard = new CreateServiceWizard(templates, project.getWrapped(), application == null ? "" : application.getWrapped().getName(), odo);
            if (WizardUtils.openWizardDialog(createServiceWizard, HandlerUtil.getActiveShell(event)) == Window.OK) {
                if (application == null) {
                    project.refresh();
                } else {
                    application.refresh();
                }
            }
        } else {
            MessageDialog.openWarning(HandlerUtil.getActiveShell(event), "Create service", "No operators installed on your cluster, can't create services");
        }
        return Status.OK_STATUS;
    } catch (IOException e) {
        String title = "Unable to create service";
        String message = e.getMessage();
        MessageDialog.open(MessageDialog.ERROR, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, message, SWT.NONE);
        return OpenShiftUIActivator.statusFactory().errorStatus(e);
    }
}
Also used : ApplicationElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement) ProjectElement(org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement) ServiceTemplate(org.jboss.tools.openshift.core.odo.ServiceTemplate) ISelection(org.eclipse.jface.viewers.ISelection) IWizard(org.eclipse.jface.wizard.IWizard) Odo(org.jboss.tools.openshift.core.odo.Odo) IOException(java.io.IOException) CreateServiceWizard(org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.CreateServiceWizard)

Aggregations

IOException (java.io.IOException)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IWizard (org.eclipse.jface.wizard.IWizard)1 Odo (org.jboss.tools.openshift.core.odo.Odo)1 ServiceTemplate (org.jboss.tools.openshift.core.odo.ServiceTemplate)1 ApplicationElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ApplicationElement)1 ProjectElement (org.jboss.tools.openshift.internal.ui.models.applicationexplorer.ProjectElement)1 CreateServiceWizard (org.jboss.tools.openshift.internal.ui.wizard.applicationexplorer.CreateServiceWizard)1