use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ImportApplicationWizard method init.
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
if (model.getConnection() != null && model.getSelectedItem() != null) {
return;
}
Connection connection = UIUtils.getFirstElement(selection, Connection.class);
if (connection != null) {
model.setConnection(connection);
} else {
IResource resource = UIUtils.getFirstElement(selection, IResource.class);
if (resource != null) {
setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(resource));
model.setSelectedItem(resource);
} else {
IProject project = UIUtils.getFirstElement(selection, IProject.class);
if (project != null) {
setModelConnection(ConnectionsRegistryUtil.safeGetConnectionFor(project));
model.setSelectedItem(project);
}
}
}
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class OpenShiftServiceRequirement method createService.
private IService createService(String serviceName, ITemplate template, String projectName, Connection connection) {
LOGGER.debug(NLS.bind("Creating service in project {0} on server {1} using template {2}", new Object[] { projectName, connection.getHost(), template.getName() }));
IProject project = OpenShift3NativeResourceUtils.getProject(projectName, connection);
assertNotNull(project);
CreateApplicationFromTemplateJob job = new CreateApplicationFromTemplateJob(project, template);
job.schedule();
new WaitWhile(new JobIsRunning(new Matcher[] { CoreMatchers.sameInstance(job) }), TimePeriod.LONG);
new WaitUntil(new NamedResourceExist(ResourceKind.SERVICE, serviceName, projectName, connection), TimePeriod.VERY_LONG);
return connection.getResource(ResourceKind.SERVICE, projectName, serviceName);
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class OpenShiftServerExtendedProperties method getWelcomePageUrl.
@Override
public String getWelcomePageUrl() throws GetWelcomePageURLException {
String welcomePageUrl = null;
try {
// Get connection explicitly to report failure. Try and connect right now to know if it fails.
// Do not catch OpenShiftException, let it be reported. We are more concerned of NPE.
Connection connection = OpenShiftServerUtils.getConnection(server);
if (connection == null || !connection.connect()) {
throw new GetWelcomePageURLException("Connection is not established.");
}
IResource resource = OpenShiftServerUtils.getResource(server, connection, new NullProgressMonitor());
if (resource == null) {
throw new GetWelcomePageURLException("Resource is missing.");
}
IProject project = resource.getProject();
if ((project != null) && (resource instanceof IService)) {
List<IRoute> routes = ResourceUtils.getRoutesFor((IService) resource, project.getResources(ResourceKind.ROUTE));
IRoute route = getRoute(OpenShiftServerUtils.getRouteURL(server), routes);
if (route == null) {
route = getRoute(routes);
}
// Reporting route == null is implemented in getRoute.
if (route != null) {
welcomePageUrl = route.getURL();
}
}
} catch (OpenShiftException e) {
throw new GetWelcomePageURLException(e.getMessage(), e);
}
return welcomePageUrl;
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class OpenShiftExplorerLabelProvider method getText.
@Override
public String getText(Object element) {
if (element instanceof IProject) {
IProject project = (IProject) element;
String name = project.getName();
if (org.apache.commons.lang.StringUtils.isNotEmpty(project.getDisplayName())) {
String[] parts = new String[] { project.getDisplayName(), name };
applyEllipses(parts);
name = parts[0] + " (" + parts[1] + ")";
}
return name;
}
return super.getText(element);
}
use of com.openshift.restclient.model.IProject in project jbosstools-openshift by jbosstools.
the class ProjectViewerComparator method compare.
/**
* Compares only projects. Other objects always go after projects and equal to each other.
* When applied to sorting a mixed array, projects go to the beginning of the array and are sorted,
* other objects go to the end without change in order.
* Project named 'default' is always the first.
* Projects with name prefixed 'openshift' go after 'default' and before all other projects.
* Finally, projects are compared by label provider, or if it is not available then by name.
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
boolean isProject1 = (e1 instanceof IProject);
boolean isProject2 = (e2 instanceof IProject);
if (!isProject1 || !isProject2) {
return (isProject1) ? -1 : (isProject2) ? LAST : 0;
}
IProject projectOne = (IProject) e1;
IProject projectTwo = (IProject) e2;
final String name1 = projectOne.getName();
final String name2 = projectTwo.getName();
if (DEFAULT_PROJECT.equals(name1)) {
return -1;
}
if (DEFAULT_PROJECT.equals(name2)) {
return 1;
}
if (name1.startsWith(OPENSHIFT_PROJECT) && !name2.startsWith(OPENSHIFT_PROJECT)) {
return -1;
}
if (!name1.startsWith(OPENSHIFT_PROJECT) && name2.startsWith(OPENSHIFT_PROJECT)) {
return 1;
}
if (labelProvider != null) {
return labelProvider.getText(e1).compareTo(labelProvider.getText(e2));
}
return name1.compareTo(name2);
}
Aggregations