Skip to content

Commit

Permalink
[JBIDE-21295] implemented #getWelcomePageUrl in server adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
adietish committed Dec 11, 2015
1 parent 37204c0 commit 95dac28
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ Require-Bundle: org.jboss.tools.openshift.common.core;bundle-version="[3.0.0,4.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Export-Package: org.jboss.tools.openshift.common.ui.wizard;
Export-Package: org.jboss.tools.openshift.common.ui.connection;
x-friends:="org.jboss.tools.openshift.core,
org.jboss.tools.openshift.express.test,
org.jboss.tools.openshift.express.ui,
org.jboss.tools.openshift.test,
org.jboss.tools.openshift.ui",
org.jboss.tools.openshift.common.ui.wizard;
x-friends:="org.jboss.tools.openshift.core,
org.jboss.tools.openshift.express.test,
org.jboss.tools.openshift.express.ui,
Expand Down
8 changes: 8 additions & 0 deletions plugins/org.jboss.tools.openshift.common.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,12 @@
</menuContribution>
</extension>

<!-- Core UI Integration: credentials prompt -->
<extension
point="org.jboss.tools.openshift.core.credentialsPrompterUI">
<credentialsPrompterUI
class="org.jboss.tools.openshift.common.ui.connection.CredentialsPrompter" />
</extension>


</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.jboss.tools.openshift.internal.common.ui.connection;
package org.jboss.tools.openshift.common.ui.connection;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.jboss.tools.common.ui.WizardUtils;
import org.jboss.tools.openshift.common.core.ICredentialsPrompter;
import org.jboss.tools.openshift.common.core.connection.IConnection;
import org.jboss.tools.openshift.internal.common.ui.OpenShiftCommonUIActivator;
import org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizard;
import org.jboss.tools.openshift.internal.common.ui.utils.UIUtils;

/**
* @author Andre Dietisheim
*/
public class CredentialsPrompter implements ICredentialsPrompter {

public CredentialsPrompter() {
// Do nothing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,25 @@ public static boolean isFirstElementOfType(Class<?> clazz, ISelection selection)
return getFirstElement(selection, clazz) != null;
}

@SuppressWarnings("unchecked")
public static <E> E getFirstElement(ISelection selection, Class<E> clazz) {
Object firstSelectedElement = getFirstElement(selection);
if (firstSelectedElement == null) {
return null;
}

if (clazz.isAssignableFrom(firstSelectedElement.getClass())) {
return (E) firstSelectedElement;
} else if (IAdaptable.class.isAssignableFrom(firstSelectedElement.getClass())) {
return (E) ((IAdaptable) firstSelectedElement).getAdapter(clazz);
} else {
return (E) Platform.getAdapterManager().getAdapter(firstSelectedElement, clazz);
}
return adapt(firstSelectedElement, clazz);
}

@SuppressWarnings("unchecked")
public static <E> E adapt(Object object, Class<E> clazz) {
if (clazz.isAssignableFrom(object.getClass())) {
return (E) object;
} else if (IAdaptable.class.isAssignableFrom(object.getClass())) {
return (E) ((IAdaptable) object).getAdapter(clazz);
} else {
return (E) Platform.getAdapterManager().getAdapter(object, clazz);
}
}

@SuppressWarnings("unchecked")
public static <E> E[] getElements(ISelection selection, Class<E> clazz) {
Object[] selectedElements = getElements(selection);
Expand Down
6 changes: 6 additions & 0 deletions plugins/org.jboss.tools.openshift.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
sourceLocatorId="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"
sourcePathComputerId="org.eclipse.jst.server.generic.core.sourcePathComputer"/>
</extension>

<!-- UI integration: credentials pompt -->
<extension-point id="org.jboss.tools.openshift.core.credentialsPrompterUI"
name="CredentialsPrompterUI"
Expand All @@ -94,4 +95,9 @@
<extension-point id="org.jboss.tools.openshift.core.sslCertificateCallbackUI"
name="SSLCertificateCallbackUI"
schema="schema/org.jboss.tools.openshift.core.sslCertificateCallbackUI.exsd"/>

<!-- UI integration: open route in browser -->
<extension-point id="org.jboss.tools.openshift.core.routeChooser"
name="RouteChooser"
schema="schema/org.jboss.tools.openshift.core.routeChooser.exsd"/>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.jboss.tools.openshift.common.core.ICredentialsPrompter"/>
<meta.attribute kind="resource"/>
</appinfo>
</annotation>
</attribute>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.jboss.tools.openshift.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appinfo>
<meta.schema plugin="org.jboss.tools.openshift.core" id="orgOpenRouteInBrowser.jboss.tools.openshift.core.routeChooser" name="RouteChooser"/>
</appinfo>
<documentation>
[Enter description of this extension point.]
</documentation>
</annotation>

<element name="extension">
<annotation>
<appinfo>
<meta.element />
</appinfo>
</annotation>
<complexType>
<sequence>
<element ref="routeChooser"/>
</sequence>
<attribute name="point" type="string" use="required">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="id" type="string">
<annotation>
<documentation>

</documentation>
</annotation>
</attribute>
<attribute name="name" type="string">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute translatable="true"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<element name="routeChooser">
<complexType>
<attribute name="class" type="string" use="required">
<annotation>
<documentation>

</documentation>
<appinfo>
<meta.attribute kind="java" basedOn=":org.jboss.tools.openshift.core.IBrowser"/>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>

<annotation>
<appinfo>
<meta.section type="since"/>
</appinfo>
<documentation>
[Enter the first release in which this extension point appears.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="examples"/>
</appinfo>
<documentation>
[Enter extension point usage example here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
[Enter API information here.]
</documentation>
</annotation>

<annotation>
<appinfo>
<meta.section type="implementation"/>
</appinfo>
<documentation>
[Enter information about supplied implementation of this extension point.]
</documentation>
</annotation>


</schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*******************************************************************************
* Copyright (c) 2015 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.core;

import java.util.List;

import com.openshift.restclient.model.route.IRoute;

/**
* UI that allows core components to let the user choose among different routes
*
* @author Andre Dietisheim
*/
public interface IRouteChooser {

public IRoute chooseRoute(List<IRoute> routes);
public void noRouteErrorDialog();

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public class OpenShiftCoreUIIntegration {

private static final String SSLCERTIFICATE_CALLBACK_UI_EXTENSION = "org.jboss.tools.openshift.core.sslCertificateCallbackUI";
private static final String CREDENTIALS_PROMPTER_UI_EXTENSION = "org.jboss.tools.openshift.core.credentialsPrompterUI";

private static final String BROWSER_EXTENSION = "org.jboss.tools.openshift.core.browser";

private static final String ATTRIBUTE_CLASS = "class";

private static OpenShiftCoreUIIntegration INSTANCE = new OpenShiftCoreUIIntegration();
Expand All @@ -36,6 +37,7 @@ public static OpenShiftCoreUIIntegration getInstance(){

protected ISSLCertificateCallback sslCertificateCallback;
protected ICredentialsPrompter credentialPrompter;
private IRouteChooser browser;

// for testing purposes
protected OpenShiftCoreUIIntegration() {
Expand All @@ -54,4 +56,12 @@ public ICredentialsPrompter getCredentialPrompter() {
}
return credentialPrompter;
}

public IRouteChooser getBrowser() {
if (browser == null) {
this.browser = ExtensionUtils.getFirstExtension(BROWSER_EXTENSION, ATTRIBUTE_CLASS);
}
return browser;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import org.eclipse.core.runtime.IAdaptable;
import org.jboss.ide.eclipse.as.core.server.internal.extendedproperties.ServerExtendedProperties;
import org.jboss.tools.openshift.core.IRouteChooser;
import org.jboss.tools.openshift.core.OpenShiftCoreUIIntegration;

import com.openshift.restclient.ResourceKind;
import com.openshift.restclient.model.IProject;
Expand All @@ -36,30 +38,40 @@ public boolean allowConvenienceEnhancements() {

@Override
public boolean hasWelcomePage() {
// return getWelcomePageUrl() != null;
return false;
}
return true;
}

@Override
public String getWelcomePageUrl() {
// checked when unfolding the context menu, cant do remoting
// org.jboss.ide.eclipse.as.ui.views.server.extensions.ShowInWelcomePageActionProvider#hasURL -> #getUrl -> props.getWelcomePageUrl()

// IService service = OpenShiftServerUtils.getService(server);
// if (service != null) {
// IProject project = service.getProject();
// if (project != null) {
// List<IRoute> routes = project.getResources(ResourceKind.ROUTE);
// if (routes != null && !routes.isEmpty()) {
// //if more than 1 route, well, we're not in the UI layer here,
// //so can't let the user select the url to open, tough luck.
// //So we pick the 1st one we find
// return routes.get(0).getURL();
// }
// }
// }
return null;
}
public String getWelcomePageUrl() {
String welcomePageUrl = null;
IService service = OpenShiftServerUtils.getService(server);
IProject project = service.getProject();
if (project != null) {
List<IRoute> routes = project.getResources(ResourceKind.ROUTE);
IRoute route = getRoute(routes);
if (route != null) {
welcomePageUrl = route.getURL();
}
}

return welcomePageUrl;
}

private IRoute getRoute(List<IRoute> routes) {
IRouteChooser chooser = OpenShiftCoreUIIntegration.getInstance().getBrowser();
IRoute route = null;

if (routes == null
|| routes.isEmpty()) {
chooser.noRouteErrorDialog();
return null;
}
if (routes.size() > 1) {
route = chooser.chooseRoute(routes);
} else {
route = routes.get(0);
}
return route;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.ui.preferences.ScopedPreferenceStore;
import org.jboss.tools.openshift.common.ui.connection.CredentialsPrompter;
import org.jboss.tools.openshift.express.core.ExpressCoreUIIntegration;
import org.jboss.tools.openshift.express.internal.core.ExpressCoreActivator;
import org.jboss.tools.openshift.express.internal.ui.console.ConsoleUtils;
import org.jboss.tools.openshift.express.internal.ui.wizard.connection.SSLCertificateCallback;
import org.jboss.tools.openshift.internal.common.ui.connection.CredentialsPrompter;
import org.osgi.framework.BundleContext;

/**
Expand Down
24 changes: 12 additions & 12 deletions plugins/org.jboss.tools.openshift.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -851,18 +851,18 @@
<sslCertificateCallbackUI
class="org.jboss.tools.openshift.internal.ui.wizard.connection.SSLCertificateCallback" />
</extension>
<!-- Core UI Integration: credentials prompt -->
<!-- Core UI Integration: route chooser -->
<extension
point="org.jboss.tools.openshift.core.credentialsPrompterUI">
<credentialsPrompterUI
class="org.jboss.tools.openshift.internal.common.ui.connection.CredentialsPrompter" />
point="org.jboss.tools.openshift.core.routeChooser">
<routeChooser
class="org.jboss.tools.openshift.internal.ui.route.RouteChooser" />
</extension>

<extension point="org.eclipse.ui.editors.documentProviders">
<provider
inputTypes="org.jboss.tools.openshift.internal.ui.property.OpenShiftResourceInput"
class="org.jboss.tools.openshift.internal.ui.property.OpenShiftResourceDocumentProvider"
id="org.jboss.tools.openshift.ui.text.OpenShiftResourceDocumentProvider">
</provider>
</extension>

<extension point="org.eclipse.ui.editors.documentProviders">
<provider
inputTypes="org.jboss.tools.openshift.internal.ui.property.OpenShiftResourceInput"
class="org.jboss.tools.openshift.internal.ui.property.OpenShiftResourceDocumentProvider"
id="org.jboss.tools.openshift.ui.text.OpenShiftResourceDocumentProvider">
</provider>
</extension>
</plugin>
Loading

0 comments on commit 95dac28

Please sign in to comment.